【发布时间】:2020-01-28 07:55:04
【问题描述】:
当我使用下面的代码制作一个绘图时,我将自定义值分配给 x 轴并设置xlim,它成功了。
x = np.array([0,1,2,3])
y = np.array([0.650, 0.660, 0.675, 0.685])
customized_x = np.array([3, 4, 5, 6])
plt.xticks(x, customized_x)
plt.xlim(2, 3)
plt.plot(x, y)
plt.show()
但是,因为我想一起制作更多的情节,所以当我改用 subplot 时,它会在ax1.set_xticks(x, customized_x) 行弹出:
fig = plt.figure(figsize=[6.0, 9.0])
ax1 = fig.add_subplot(111)
x = np.array([0,1,2,3])
y = np.array([0.650, 0.660, 0.675, 0.685])
customized_x = np.array([3, 4, 5, 6])
ax1.set_xticks(x, customized_x)
ax1.set_xlim(2, 3)
ax1.plot(x, y)
plt.show()
得到的错误:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
虽然 我可以通过不使用子图来避免这个问题,我仍然想知道子图有什么问题?
编辑
我找到了solution to the similar question here。抱歉重复了。
【问题讨论】:
标签: python matplotlib