Matplotlib - how to change the sign of the axes of the base exponent

Reasonably new to python, and I have code like this

V = [0, 0.003, 0, 0.0002] pylab.axis(V) legend_font_props = FontProperties() legend_font_props.set_size('small') pylab.xlabel('Time (ms)') pylab.xticks(rotation=45) pylab.xticks.set_major_formatter(FixedOrderFormatter(-3)) pylab.ylabel('Current (A)') pylab.title('Title') pylab.plot(Temp0_Xvals, Temp0_Yvals, marker='+') pylab.plot(Temp10_Xvals, Temp10_Yvals, marker='+') pylab.plot(Temp20_Xvals, Temp20_Yvals, marker='+') pylab.plot(Temp30_Xvals, Temp30_Yvals, marker='+') pylab.plot(Temp40_Xvals, Temp40_Yvals, marker='+') pylab.plot(Temp50_Xvals, Temp50_Yvals, marker='+') pylab.plot(Temp60_Xvals, Temp60_Yvals, marker='+') pylab.plot(Temp70_Xvals, Temp70_Yvals, marker='+') pylab.plot(Temp80_Xvals, Temp80_Yvals, marker='+') pylab.show() 

I want to change the baseline of my x shortcuts because they take up a lot of space and will look better if I just add units to the x-axis header. I found code that does exaccty what i want below

 fig = plt.figure() ax = fig.add_subplot(111) ax.plot(x, y, 'b-') ax.yaxis.set_major_formatter(FixedOrderFormatter(-9)) plt.show() 

Obviously, they use a different format for the way I'm trying to do this, and I cannot find a way to convert ax.yaxis.set_major_formatter (FixedOrderFormatter (-9)) to my code.

Is there a way to do what I want without rewriting my code?

+4
source share
1 answer

Are you just asking how to get the current axis object using the pylab interface?

It's simple:

 ax = pylab.gca() 

However, I highly recommend not using the pylab interface. This is valid for interactive use only. At the very least, switch to using matplotlib.pyplot instead of pylab . pylab is a huge namespace. It is easier to work with numpy and matplotlib separately instead of rolling them into the same namespace.

0
source

Source: https://habr.com/ru/post/1398739/


All Articles