[英]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. 我试图制作一个“ ylim”,“ xlim”,但它没有任何改变。
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. 我想拥有的是,我可以强制绘图显示为例如从2-3.2开始,并且在拐角处会有一个1e + 3,并且x轴类似。 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). 可悲的是,该图是自动缩放的,因此它a)不能使图最理想,并且b)有时隐藏一些点或将第一个点切成两半(因此只显示了一半)。
It would be great if you could help me fix that. 如果您能帮助我解决该问题,那就太好了。 As said before: I have google it, but it doesn't worked. 如前所述:我有google,但没有用。 What I have tried: 我试过的
Hopefully you can help me? 希望你能帮助我?
Kind regards! 亲切的问候! And thank you very much in advance! 并非常感谢您!
xlim
and ylim
to the data, you should use autoscale(True, tight=True)
要强制将xlim
和ylim
应用于数据,应使用autoscale(True, tight=True)
set_powerlimits
function of the default ticks formatter. 若要在使用科学计数法时使用阈值,请使用默认刻度格式器的set_powerlimits
函数。 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.