2017-03-02 70 views
1

比方說,我有這樣的代碼:替換x軸值

nbrs = np.array([0, 13, 13, 7, -9, 0]) 
x_values = np.array([0, 50, 100, 150, 200, 250]) 
plt.plot(nbrs) 
plt.xticks(my_xticks) 

enter image description here

當我試圖xticks它不工作:

nbrs = np.array([0, 13, 13, 7, -9, 0]) 
x_values = np.array([0, 50, 100, 150, 200, 250]) 
plt.plot(nbrs) 
plt.xticks(my_xticks) 

enter image description here

代替[1, 2, 3, 4, 5]我想擁有[0, 50, 100, 150, 200, 250]

回答

1

簡單:

plt.plot(x_values,nbrs) 
0

你應該通過你的x值的plt.plot功能。無需使用plt.xticks。就像這樣:

import numpy as np 
import matplotlib.pyplot as plt 

nbrs = np.array([0, 13, 13, 7, -9, 0]) 
x_values = np.array([0, 50, 100, 150, 200, 250]) 
plt.plot(x_values,nbrs) 

console output