【问题标题】:Evenly space for x-ticks in MatplotlibMatplotlib 中 x-ticks 的均匀空间
【发布时间】:2021-07-27 01:54:54
【问题描述】:

我需要绘制这种风格的图表,其中 x-ticks 在 [0.1, 1, 10, 100, 1000] 的范围内均匀分布。

我的代码如下所示:

x = np.array([0.3081, 1.2, 29.4, 29.4, 54.7, 29.4, 14.7, 7.8, 54.7, 68.0])
y =np.array( [94.92, 94.85, 92.61, 93.44, 94.86, 92.57, 94.88, 93.64, 94.99, 95.40])

plt.plot(x, y, 'b.')
plt.xticks(np.array([0.1, 1, 10, 100]))
plt.grid(True)
plt.show()

生成这样的图:

任何帮助或建议将不胜感激!

【问题讨论】:

    标签: python matplotlib xticks


    【解决方案1】:

    您可以使用matplotlib.pyplot 方法xscale 并将'log' 作为参数传递:

    import numpy as np
    import matplotlib.pyplot as plt
    
    x = np.array([0.3081, 1.2, 29.4, 29.4, 54.7, 29.4, 14.7, 7.8, 54.7, 68.0])
    y = np.array([94.92, 94.85, 92.61, 93.44, 94.86, 92.57, 94.88, 93.64, 94.99, 95.40])
    
    plt.plot(x, y, 'b.')
    plt.xticks(np.array([0.1, 1, 10, 100]))
    plt.xscale('log')
    plt.grid(True)
    plt.show()
    

    【讨论】:

      猜你喜欢
      • 2019-06-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-27
      • 2023-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多