Using negative values ​​in matplotlib sheet

Starting with this example , I would like to do something very similar, but am able to use negative values ​​for variables in my code, for example

menMeans   = (-20, 35, -30, 35, -27)
womenMeans = (25, -32, 34, -20, 25)

      

although it has nothing to do with the meaning of men and women. But when I do this, I don't see anything to do with negative values ​​in the plot. I also change the Y scale,

plt.yticks(np.arange(-81,81,10))

      

but nothing. Any hints?

+3


source to share


2 answers


I change the scale of the axis y

to the following command:

plt.ylim([-81,81])

      

which will set the scale of the axis y

from -81 to 81



for the axis of the scale x

, which will be

plt.xlim([ xmin,xmax])

      

+2


source


in the gallery example you will find this line of code:

plt.bar(ind, womenMeans, width, color='y',bottom=menMeans, yerr=menStd)

      

the bottom value can be set to negative so that the bar starts somewhere negative and is womenMeans

long.



yellow bar from -200 to 20 at x = 5 with width = 10

:

plt.bar(5, 220,10, color='y',bottom=-200)

      

0


source







All Articles