Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Apprendre Horizontal Bar Chart | Bar Charts
Visualization in Python with matplotlib

bookHorizontal Bar Chart

Horizontal bar charts are the same as bar charts, but have axes 'swapped': this time bars are horizontal, and values are labeled on the x-axis.

To build horizontal bar chart. use the .barh() function. This function can also be used to build stacked bars, but this time instead of the bottom parameter we should use the left parameter, and instead of width we should use height. For example, we can rebuild the stacked bar chart from example as a horizontal one:

1234567891011121314151617181920
# Import library import matplotlib.pyplot as plt # Create data for chart countries = ['United States', 'India', 'Brazil'] agricultural = [333600, 1458996, 214368] industrial = [3722590, 2179020, 672336] services = [15592000, 5826510, 2361296] # Create Axes and Figure objects fig, ax = plt.subplots() # Initialize bar chart ax.barh(countries, agricultural, label = 'Agricultural', height = 0.4) ax.barh(countries, industrial, label = 'Industrial', left = agricultural, height = 0.4) ax.barh(countries, services, label = 'Services', left = industrial, height = 0.4) # Display the plot plt.legend() plt.show()
copy

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 7

Demandez à l'IA

expand

Demandez à l'IA

ChatGPT

Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion

Awesome!

Completion rate improved to 2.94

bookHorizontal Bar Chart

Glissez pour afficher le menu

Horizontal bar charts are the same as bar charts, but have axes 'swapped': this time bars are horizontal, and values are labeled on the x-axis.

To build horizontal bar chart. use the .barh() function. This function can also be used to build stacked bars, but this time instead of the bottom parameter we should use the left parameter, and instead of width we should use height. For example, we can rebuild the stacked bar chart from example as a horizontal one:

1234567891011121314151617181920
# Import library import matplotlib.pyplot as plt # Create data for chart countries = ['United States', 'India', 'Brazil'] agricultural = [333600, 1458996, 214368] industrial = [3722590, 2179020, 672336] services = [15592000, 5826510, 2361296] # Create Axes and Figure objects fig, ax = plt.subplots() # Initialize bar chart ax.barh(countries, agricultural, label = 'Agricultural', height = 0.4) ax.barh(countries, industrial, label = 'Industrial', left = agricultural, height = 0.4) ax.barh(countries, services, label = 'Services', left = industrial, height = 0.4) # Display the plot plt.legend() plt.show()
copy

Tout était clair ?

Comment pouvons-nous l'améliorer ?

Merci pour vos commentaires !

Section 2. Chapitre 7
some-alt