Python Argument Argument MatPlot Arguments

I am trying to create a histogram using the matplot library, but I cannot figure out what arguments are for this function.

The documentation says bar(left, height) , but I don’t know how to place my data [which is a list of numbers named x] here.

He tells me that the height should be scalar when I put it as the number 0.5 or 1 , and does not show me an error if the height is a list.

+6
python matplotlib graph
source share
2 answers

A simple thing you can do:

 plt.bar(range(len(x)), x) 

left are the left ends of the bars. You say where to place the columns on the horizontal axis. Here you can play until you get it:

 >>> import matplotlib.pyplot as plt >>> plt.bar(range(10), range(20, 10, -1)) >>> plt.show() 
+4
source share

From the documentation http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.bar

 bar(left, height, width=0.8, bottom=0, **kwargs) 

Where:

 Argument Description left --> the x coordinates of the left sides of the bars height --> the heights of the bars 

A simple example from http://scienceoss.com/bar-plot-with-custom-axis-labels/

 # pylab contains matplotlib plus other goodies. import pylab as p #make a new figure fig = p.figure() # make a new axis on that figure. Syntax for add_subplot() is # number of rows of subplots, number of columns, and the # which subplot. So this says one row, one column, first # subplot -- the simplest setup you can get. # See later examples for more. ax = fig.add_subplot(1,1,1) # your data here: x = [1,2,3] y = [4,6,3] # add a bar plot to the axis, ax. ax.bar(x,y) # after you're all done with plotting commands, show the plot. p.show() 
+2
source share

All Articles