This blog post is derived from Python Data Visualization (edited by Dark Horse Programmer). It first explains how the bar parameter is used, and then demonstrates stacked bar chart and bar chart with error drawing respectively.
Bar parameters
bar(x,height,width=0.8,bottom=None,align='center',data=None, tick_label=None,xerr=None,yerr=None,error_kw=None,**kwargs)
The common parameters of this function are as follows:
- x denotes the coordinate value of x
- height: the height of the bar
- width: the width of the bar, default is 0.8
- bottom: the y-coordinate of the bottom of the bar, default is 0.
- align: the alignment of the bar, there are two values: 'center' and 'edge', where 'center' means align the bar with the center of the scale, and 'edge' means align the left side of the bar with the scale.
- tick_label: indicates the scale label of the bar.
- xerr,yerr: if not set to None, you need to add horizontal/vertical error bars to the bar chart.
- error_kw: a dictionary of attributes of the error bar, the keys of which correspond to the keyword arguments of the errorbar() function.
Example: Stacked Bar Chart Demo
import as plt import numpy as np x = (5) y1 = ([10,8,7,11,13]) y2 = ([9,6,5,10,12]) (x,y1,tick_label=['a','b','c','d','e'],width=bar_width) (x,y2,bottom=y1,width=bar_width) ()
Example: Stacked graph with error bars
import as plt import numpy as np x = (5) y1 = ([10, 8, 7, 11, 13]) error = [2, 1, 2.5, 2, 1.5] bar_width = 0.3 # Plotting bar graphs with error bars (x, y1, tick_label=['a', 'b', 'c', 'd', 'e'], width=bar_width) (x, y1, bottom=y1, width=bar_width, yerr=error) ()
To this point this article on Python using bar to draw stacked/bar with error bar graph implementation of the article is introduced to this, more related Python bar bar graph content, please search for my previous posts or continue to browse the following related articles I hope you will support me in the future more!