2017-03-02 61 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