Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Bar Chart | Creating Commonly Used Plots
Ultimate Visualization with Python
course content

Contenido del Curso

Ultimate Visualization with Python

Ultimate Visualization with Python

1. Matplotlib Introduction
2. Creating Commonly Used Plots
3. Plots Customization
4. More Statistical Plots
5. Plotting with Seaborn

Bar Chart

A bar chart, also known as a bar graph, is a visual representation where categorical data is displayed using rectangular bars. The height or length of these bars is directly proportional to the values they depict. Without further ado, let’s have a look at the bar chart implementation in matplotlib:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Creating a bar chart with separate colors for each bar plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow']) plt.show()
copy

Required Parameters

In this example, we utilize the bar() function from pyplot to create a bar chart. We provide a list of programming language names for the x-axis as the first argument (x) and the respective bar heights representing popularity percentages as the second argument (height).

Optional Parameters

Using the color keyword argument, we speicfy the list of color names. By default, all bars will have a bluish color.

Another important optional parameter is width and stands for the width(s) of the bars, its default value is 0.8. It can either be a single float number, meaning equal width for each bar, or an array of floats, in which each element corresponds to the width of the respective bar. Let’s change this parameter for our example:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Specify the bars colors and widths plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow'], width=[0.9, 0.7, 0.5, 0.3]) plt.show()
copy

We can clearly see that the width decreases from left to right, that’s exactly what we expected.

As with other plots, you can always refer to the documentation for a quick lookup of the bar() function syntax and all of its parameters.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 2. Capítulo 4
toggle bottom row

Bar Chart

A bar chart, also known as a bar graph, is a visual representation where categorical data is displayed using rectangular bars. The height or length of these bars is directly proportional to the values they depict. Without further ado, let’s have a look at the bar chart implementation in matplotlib:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Creating a bar chart with separate colors for each bar plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow']) plt.show()
copy

Required Parameters

In this example, we utilize the bar() function from pyplot to create a bar chart. We provide a list of programming language names for the x-axis as the first argument (x) and the respective bar heights representing popularity percentages as the second argument (height).

Optional Parameters

Using the color keyword argument, we speicfy the list of color names. By default, all bars will have a bluish color.

Another important optional parameter is width and stands for the width(s) of the bars, its default value is 0.8. It can either be a single float number, meaning equal width for each bar, or an array of floats, in which each element corresponds to the width of the respective bar. Let’s change this parameter for our example:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Specify the bars colors and widths plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow'], width=[0.9, 0.7, 0.5, 0.3]) plt.show()
copy

We can clearly see that the width decreases from left to right, that’s exactly what we expected.

As with other plots, you can always refer to the documentation for a quick lookup of the bar() function syntax and all of its parameters.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

Sección 2. Capítulo 4
toggle bottom row

Bar Chart

A bar chart, also known as a bar graph, is a visual representation where categorical data is displayed using rectangular bars. The height or length of these bars is directly proportional to the values they depict. Without further ado, let’s have a look at the bar chart implementation in matplotlib:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Creating a bar chart with separate colors for each bar plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow']) plt.show()
copy

Required Parameters

In this example, we utilize the bar() function from pyplot to create a bar chart. We provide a list of programming language names for the x-axis as the first argument (x) and the respective bar heights representing popularity percentages as the second argument (height).

Optional Parameters

Using the color keyword argument, we speicfy the list of color names. By default, all bars will have a bluish color.

Another important optional parameter is width and stands for the width(s) of the bars, its default value is 0.8. It can either be a single float number, meaning equal width for each bar, or an array of floats, in which each element corresponds to the width of the respective bar. Let’s change this parameter for our example:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Specify the bars colors and widths plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow'], width=[0.9, 0.7, 0.5, 0.3]) plt.show()
copy

We can clearly see that the width decreases from left to right, that’s exactly what we expected.

As with other plots, you can always refer to the documentation for a quick lookup of the bar() function syntax and all of its parameters.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones

¿Todo estuvo claro?

A bar chart, also known as a bar graph, is a visual representation where categorical data is displayed using rectangular bars. The height or length of these bars is directly proportional to the values they depict. Without further ado, let’s have a look at the bar chart implementation in matplotlib:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Creating a bar chart with separate colors for each bar plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow']) plt.show()
copy

Required Parameters

In this example, we utilize the bar() function from pyplot to create a bar chart. We provide a list of programming language names for the x-axis as the first argument (x) and the respective bar heights representing popularity percentages as the second argument (height).

Optional Parameters

Using the color keyword argument, we speicfy the list of color names. By default, all bars will have a bluish color.

Another important optional parameter is width and stands for the width(s) of the bars, its default value is 0.8. It can either be a single float number, meaning equal width for each bar, or an array of floats, in which each element corresponds to the width of the respective bar. Let’s change this parameter for our example:

123456
import matplotlib.pyplot as plt programming_languages = ['Python', 'Java', 'C#', 'C++'] shares = [40, 30, 17, 13] # Specify the bars colors and widths plt.bar(programming_languages, shares, color=['blue', 'green', 'red', 'yellow'], width=[0.9, 0.7, 0.5, 0.3]) plt.show()
copy

We can clearly see that the width decreases from left to right, that’s exactly what we expected.

As with other plots, you can always refer to the documentation for a quick lookup of the bar() function syntax and all of its parameters.

Tarea

  1. Use the correct function to create a bar chart.
  2. Pass countries and gdp_list in this function in the correct order.
  3. Use the proper keyword argument to specify the width of the bars.
  4. Fill the list for this keyword argument with the following values 0.6, 0.9, 0.45, 0.2 from left to right.

Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
Sección 2. Capítulo 4
Cambia al escritorio para practicar en el mundo realContinúe desde donde se encuentra utilizando una de las siguientes opciones
We're sorry to hear that something went wrong. What happened?
some-alt