【问题标题】:Awkward scientific notation on the axis in matplotlibmatplotlib 中轴上的尴尬科学记数法
【发布时间】:2020-11-25 23:51:28
【问题描述】:

所以我想改变数字在 x 和 y 轴上的显示方式。我要么不希望任何权力被代表,要么希望每个单独的勾号中的权力。这可能吗?

indx = np.where(time > 0.28549) # indexs where i want to zoom in
plt.plot(time[indx], dist[indx], label='Without air resistance')
plt.plot(time[indx], distd[indx], label='With air resistance')
plt.xlabel('Time / s')
plt.ylabel('Distance from $y_0$ / m')
plt.ticklabel_format(style='plain')
plt.title('A closer look at the distance-time graph')
plt.legend()
print(time[-1])

graph

谢谢。

【问题讨论】:

    标签: python matplotlib xticks


    【解决方案1】:

    您可以使用刻度格式化程序

    from matplotlib.ticker import FormatStrFormatter
    
    time = np.linspace(0.285489, 0.285493, 100)
    dist = 2*time
    distd = 2*time+0.0000025
    indx = np.where(time > 0.28549) # indexs where i want to zoom in
    plt.plot(time[indx], dist[indx], label='Without air resistance')
    plt.plot(time[indx], distd[indx], label='With air resistance')
    plt.xlabel('Time / s')
    plt.ylabel('Distance from $y_0$ / m')
    plt.ticklabel_format(style='plain')
    
    ### Format the tick labels, does nothing to the value.
    plt.gca().xaxis.set_major_formatter(FormatStrFormatter('%.7f'))
    plt.gca().yaxis.set_major_formatter(FormatStrFormatter('%.7f'))
    
    plt.title('A closer look at the distance-time graph')
    plt.legend()
    

    然而,就个人观点而言,我认为 matplotlib 默认看起来更好,因为考虑到如此令人分心的小数位数,它可以更容易地计算出刻度间隔。

    【讨论】:

      猜你喜欢
      • 2018-10-13
      • 2014-11-03
      • 2022-01-22
      • 1970-01-01
      • 1970-01-01
      • 2014-11-16
      • 1970-01-01
      相关资源
      最近更新 更多