【发布时间】:2022-08-09 20:51:58
【问题描述】:
请问如何切换x轴上的刻度而不改变绘图?我尝试了命令的行。
import matplotlib.pyplot as plt
x1 = [1, 2, 3]
x2 = [1, 2, 3, 4, 5, 6]
y2 = [1.2, 2, 2.5, 3.0, 3.1, 5.3]
fig, ax = plt.subplots(figsize=(10, 6))
plt.xlim(-2,2+max(len(x1), len(x2)))
plt.scatter(x1, x1, c= \'red\')
plt.scatter(x2, y2, c = \'green\')
ax.tick_params(axis=\'x\')
ax2 = ax.twinx()
ax3 = ax.twiny()
ax2.set_ylim(ax.get_ylim())
ax3.set_xlim(-2,2+len(x1))
ax3.tick_params(axis=\'x\')
ax.tick_params(axis=\'x\', colors=\'red\')
ax3.tick_params(axis=\'x\', colors=\'green\')
#ax.set_xlim(-2,2+len(x1))
#ax3.set_xlim(-2,2+len(x2))
plt.show()
我想要下轴数据 x1 的 -2,2+len(x1) 范围和上轴 x2 的 -2,2+len(x2) 范围,并将其分布在 -2,2+ 的范围内最大(长度(x2),长度(x1))。
标签: python-3.x matplotlib axes