控制matplotlib中xtick的值

2024-04-26 18:50:50 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我可能遗漏了一些很明显的东西,但是。。。在

我使用以下代码:

import matplotlib.pyplot as plt
import numpy as np

def f(t):
    A = 2409.505
    rho = 0.3260
    C = 0.00
    if C == 0.0:
        return (A*np.exp(-t/rho))
    else:
        return (A*np.exp(-t/rho)) - (C/r**6)

t1 = np.arange(0, 15, 0.01)
plt.ylim(-0.005, 100)
plt.plot(f(t1), 'b')
plt.tick_params(top = 'off', right = 'off')
plt.grid(linestyle = '--', linewidth = 0.05)
plt.show()

生成以下绘图: enter image description here

但是,我希望XTICK的标签是1-16。有人能帮忙吗?在

干杯!在


Tags: 代码importnumpyreturnifmatplotlibdefas
2条回答
plt.plot(t1, f(t1), 'b')

如果只传递1D数组\列表进行绘图。它假定x轴是1, 2, 3, ..到数组\列表的长度

需要在plot函数中传递数组t1作为x变量:

plt.plot(t1, f(t1), 'b')

相关问题 更多 >