Python 使用myplotlib重复x轴值
我有下面的数据,我想用重复的x轴绘制图表Python 使用myplotlib重复x轴值,python,matplotlib,Python,Matplotlib,我有下面的数据,我想用重复的x轴绘制图表 | 30 | | 0.650297475 | | 40 | | 0.657665519 | | 50 | | 0.669169975 | | 60 | | 0.695916956 | | 50 | | 0.680254894 | | 40 | | 0.663912144 | | 30 | | 0.653692469 | | 20 | | 0.644423894 | | 10 | | 0.637784575 | | 0 | | 0.6
| 30 | | 0.650297475 |
| 40 | | 0.657665519 |
| 50 | | 0.669169975 |
| 60 | | 0.695916956 |
| 50 | | 0.680254894 |
| 40 | | 0.663912144 |
| 30 | | 0.653692469 |
| 20 | | 0.644423894 |
| 10 | | 0.637784575 |
| 0 | | 0.626213656 |
| 10 | | 0.637769063 |
| 20 | | 0.643006988 |
| 30 | | 0.646742206 |
| 50 | | 0.668539731 |
| 60 | | 0.694959931 |
| 50 | | 0.679511669 |
| 40 | | 0.6633013 |
| 30 | | 0.653026313 |
| 20 | | 0.644970369 |
| 10 | | 0.63772925 |
| 0 | | 0.626494163 |
| 20 | | 0.643006456 |
| 30 | | 0.646692806 |
| 40 | | 0.656562469 |
| 50 | | 0.668683988 |
| 60 | | 0.695289806 |
| 50 | | 0.680420325 |
| 40 | | 0.663145675 |
| 30 | | 0.654077156 |
我正在尝试使用myplotlib绘制它
x=range(len(x_axis))
fig = plt.figure()
ax = plt.gca()
ax.ticklabel_format(useOffset=False)
ax.set_xticks(x_axis, minor=True)
CH1 = ax.plot(x, y_axis)
ax.legend([parameter])#,bbox_to_anchor=(1.05, 1),loc=2, borderaxespad=0
fig.savefig("plotfile_get_Vendor_version_here"+".png")
plt.close(fig)
但x轴值在30处终止。
我知道这是因为范围函数。不管怎样,我都能解决这个问题。
我真的会帮上忙的
问候,,
Pavan您需要
ax.setxticks()
来设置刻度位置,并ax.setxticklabels()
来实际打印刻度。尝试:
import numpy as np
import matplotlib.pyplot as plt
# the data:
x_axis = np.array(
[ 30., 40., 50., 60., 50., 40., 30., 20., 10., 0., 10.,
20., 30., 50., 60., 50., 40., 30., 20., 10., 0., 20.,
30., 40., 50., 60., 50., 40., 30.])
y_axis = np.array(
[ 0.65029748, 0.65766552, 0.66916997, 0.69591696, 0.68025489,
0.66391214, 0.65369247, 0.64442389, 0.63778457, 0.62621366,
0.63776906, 0.64300699, 0.64674221, 0.66853973, 0.69495993,
0.67951167, 0.6633013 , 0.65302631, 0.64497037, 0.63772925,
0.62649416, 0.64300646, 0.64669281, 0.65656247, 0.66868399,
0.69528981, 0.68042033, 0.66314567, 0.65407716])
x=range(len(x_axis))
fig, ax = plt.subplots(1, 1)
ax.set_xticks(x) # set tick positions
# Labels are formated as integers:
ax.set_xticklabels(["{:d}".format(int(v)) for v in x_axis])
ax.plot(x, y_axis)
fig.canvas.draw() # actually draw figure
plt.show() # enter GUI loop (for non-interactive interpreters)
或者,您也可以尝试类似于的方法,非常感谢。诀窍在于使用ax.setxticklabels。我成功地解决了这个问题。我希望x轴显示连续的值,即30,40,50,60,10,20,30,40…如果不使用xtricks,python将使轴混乱,因此我只得到10,20,30,40,50,60。我真的不明白你想做什么。“重复x轴”是什么意思?