我是 Python pyplot 的本科生新手。我想要做的是针对序列绘制一个函数,例如,x = [1,2,3,4,5].
该pyplot.plot函数自然给出了一个漂亮的数字。但我想在 x 轴上用一个字符串替换刻度标签“2”,说“关键点”,同时使刻度标签,例如,“4”和“5”不可见。我怎样才能做到这一点pyplot?
您的帮助将不胜感激。
这是你如何做到的:
from matplotlib import pyplot as plt
x = [1,2,3,4,5]
y = [1,2,0,2,1]
plt.clf()
plt.plot(x,y,'o-')
ax = plt.gca() # grab the current axis
ax.set_xticks([1,2,3]) # choose which x locations to have ticks
ax.set_xticklabels([1,"key point",2]) # set the labels to display at those ticks
Run Code Online (Sandbox Code Playgroud)
通过从 xtick 列表中省略 4 和 5,它们将不会显示。
| 归档时间: |
|
| 查看次数: |
10081 次 |
| 最近记录: |