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

Bar ChartBar 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:

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:

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.

Завдання

  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.

Все було зрозуміло?

Секція 2. Розділ 4
toggle bottom row
course content

Зміст курсу

Ultimate Visualization with Python

Bar ChartBar 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:

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:

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.

Завдання

  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.

Все було зрозуміло?

Секція 2. Розділ 4
toggle bottom row
some-alt