【问题标题】:Scale of x/y-axis and automate scale of point and windowx/y 轴的比例和点和窗口的自动比例
【发布时间】:2015-09-15 23:32:29
【问题描述】:
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()

正如你在我的情节中看到的那样:轴比例是可怕的。而且我不知道如何改变它。 Of cause I've searched for help, but this example doesn't work for me。我尝试制作“ylim”、“xlim”,但它并没有改变任何东西。

我想要的是,我可以强制绘图显示例如从 2-3.2 并且在角落里会有一个 1e+3 和类似的 x 轴。如果可能的话,十的幂也不错。

还有我的第二个缩放问题:我使用了自动缩放,但它好像什么也没做?遗憾的是,该图是自动缩放的,因此它 a) 不能以最佳方式填充该图,并且 b) 有时会隐藏一些点或将第一个点切成两半(因此只显示了一半)。

如果您能帮我解决这个问题,那就太好了。如前所述:我有谷歌它,但它不起作用。我尝试过的:

  • xlim 和 ylim 强制绘图按 1e-X 和 1e+X 进行缩放
  • 使用自动缩放让绘图更适合我缩放图表

希望你能帮助我吗?

亲切的问候!并提前非常感谢您!

【问题讨论】:

    标签: python matplotlib plot


    【解决方案1】:

    这是您的代码的更新版本:

    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()
    

    【讨论】:

      猜你喜欢
      • 2015-06-10
      • 2015-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-10-30
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多