[英]How can I rotate a plot x axis and y axis using pyplot
如果您不关心刻度上是否为负数,则可以简单地执行以下操作: plt.scatter([-y for y in y1], x1)
您还需要更改轴上的标签,但这将在垂直轴上绘制x,在水平负值上绘制y,以便从右到左移动。
另一方面,如果要旋转图像,则可以将其保存并旋转到文件,使用其他工具旋转并读取该文件。
如果不完全重写,则无法旋转图上的工具栏。 这似乎工作量太大,所以我省去了。
除此之外,旋转图中的所有元素并交换x和y轴的角色没有大问题。 特别,
rotation
参数。 scatter(y,x)
。 ax.invert_xaxis()
ax.yaxis.tick_right()
强制代码:
import matplotlib.pyplot as plt
x1 = [0, 0.02, 0.04, 0.08, 0.12, 0.16, 0.2]
y1 = [0.0005, 0.052, 0.0905, 0.1675, 0.2485, 0.3225, 0.4035]
fig,ax=plt.subplots(figsize=plt.rcParams["figure.figsize"][::-1])
fig.subplots_adjust(left=0.1, right=0.875, top=0.9,bottom=0.125)
ax.scatter(y1, x1)
ax.set_ylabel("x", rotation=90)
ax.yaxis.tick_right()
ax.yaxis.set_label_position("right")
ax.set_xlabel("y", rotation=180)
ax.invert_xaxis()
plt.setp(ax.get_xticklabels(), rotation=90, va="top", ha="center")
plt.setp(ax.get_yticklabels(), rotation=90, va="center", ha="left")
ax.text(-0.05,0.5,"y-x scatter", ha="center", va="center",
transform=ax.transAxes, rotation=90)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.