【问题标题】:Python implementation of non uniform (non linear) x-axis in matplotlibmatplotlib中非均匀(非线性)x轴的Python实现
【发布时间】:2020-03-31 16:50:58
【问题描述】:

我正在尝试使用 matplotlib 在 Python 中使用非线性 x 轴,但没有找到任何函数或解决此问题。

这就是我们的graph 在这个时间点上的样子,我想把它转换成类似this. 的东西(看看两个图的 x 轴的差异)

我现在的代码是:

plt.axis([0, 100, 0, 1])
plt.plot(onecsma_x, onecsma_y, label='1-CSMA')
plt.plot(slotted_aloha_x,slotted_aloha_y, label ='Slotted Aloha')
plt.plot(pure_aloha_x,pure_aloha_y, label ='Pure Aloha')
plt.plot(npcsma_x, npcsma_y, label ='Non persisten CSMA')
plt.plot(pcsma_x, pcsma_y, label ='P persistent CSMA')
plt.legend(loc='upper right')
plt.show()

【问题讨论】:

    标签: python matplotlib graph axes


    【解决方案1】:

    对于日志 x 轴,使用 semilogx 而不是 plot

    你也可以在使用semilogx(但在show之前)之后限制x轴:

    plt.xlim(0, 10**2)
    

    【讨论】:

    • 在对数轴中使用 0 不是一个好主意。更好的 0.0001 左右,具体取决于应用程序。 Log(0) 是负无穷大,因此 0 不可能位于对数轴上。
    • @JohanC 一开始就意识到这一点并从 0.01 而不是 0 开始。无论如何,谢谢!
    猜你喜欢
    • 2018-12-03
    • 1970-01-01
    • 2012-12-08
    • 1970-01-01
    • 2020-04-08
    • 1970-01-01
    • 2021-09-07
    • 1970-01-01
    • 2010-12-04
    相关资源
    最近更新 更多