簡體   English   中英

更改 matplotlib 中 x 軸的值

[英]Change values of x-axis in matplotlib

import matplotlib.pyplot as plt
import numpy as np

fig = plt.figure()
ax1 = fig.add_axes([0, 0, 1, 1])
input = np.arange(11,21,1)
sin = np.sin(input)
ax1.plot(sin)
plt.show()

我有上面的代碼,它顯示了 plot,給定輸入的正弦值從 11 到 20,但 x 軸刻度顯示的值從 0 到 10。我希望它從 11 到 20。我該怎么做或難道我做錯了什么?

(實際上,如果我 plot 圖表從 0 到 21 並且當我將 plot 從 11 截斷到 21 時,它會起作用。有了這個:

np.arange(0, 21, 1)

ax1.set_xlim([11, 21])

這是唯一的方法嗎?

ax1.plot(input, sin)

使用input命名變量也是一種不好的做法,因為它是一個關鍵字

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM