简体   繁体   中英

Scale of x/y-axis and automate scale of point and window

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

x=np.linspace(2.0, 3.0, num=100)*1e-5
y=np.linspace(2.0, 3.0, num=100)*1e3

slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
predict_y = intercept + slope * x

plt.plot(x,y,'go')
plt.plot(x, predict_y, 'k-')
plt.legend(('data', 'line-regression'), 'upper left')
plt.autoscale(True)
plt.grid(True)
plt.show()

As you can see at my plot: the axis scale is horrorfull. And I don't know how to change it. Of cause I've searched for help, but this example doesn't work for me . I've tried to make a "ylim", "xlim" but it doesn't change anything.

What I would love to have is, that I can force the plot to show for example from 2-3.2 and in the corner there would be a 1e+3 and similar for the x-axis. If possible a power of ten would be nice too.

And my second scaling problem: I've used autoscale, but it's like it doesn't do anything? Sadly the plot is scaled automatically, so it a) doesn't fill the plot optimal and b) some times hide some of the points or cut the first point in halfs (so just a half is shown).

It would be great if you could help me fix that. As said before: I have google it, but it doesn't worked. What I have tried:

  • xlim and ylim to force the plot to scale with 1e-X and 1e+X
  • used autoscale to let the plot scale the graph better for me

Hopefully you can help me?

Kind regards! And thank you very much in advance!

地磅功率10

Here is an updated version of your code:

import numpy as np
import matplotlib.pyplot as plt
from scipy import stats

x=np.linspace(2.0, 3.0, num=100)*1e-5
y=np.linspace(2.0, 3.0, num=100)*1e3

slope, intercept, r_value, p_value, std_err = stats.linregress(x,y)
predict_y = intercept + slope * x

plt.plot(x,y,'go')
plt.plot(x, predict_y, 'k-')
plt.legend(('data', 'line-regression'), 'upper left')
plt.autoscale(True, tight=True)
plt.gca().get_xaxis().get_major_formatter().set_powerlimits((-3, 3))
plt.grid(True)
plt.show()

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM