繁体   English   中英

如何旋转简单的matplotlib轴

[英]How to rotate a simple matplotlib Axes

是否可以像旋转matplotlib.text.Text一样旋转matplotlib.axes.Axes

# text and Axes instance
t = figure.text(0.5,0.5,"some text")
a = figure.add_axes([0.1,0.1,0.8,0.8])
# rotation
t.set_rotation(angle)
a.set_rotation()???

在文本实例上使用简单的set_rotation会将文本绕其坐标轴旋转角度值。 有没有办法对轴实例执行相同的操作?

您是否在问如何旋转整个轴(而不仅仅是文本)?

如果是这样,是的,这是可能的,但是您必须事先知道绘图的范围。

您将不得不使用axisartist ,它允许像这样的更复杂的关系,但是稍微复杂一点,并不意味着交互式可视化。 如果尝试缩放等,则会遇到问题。

import matplotlib.pyplot as plt
from matplotlib.transforms import Affine2D
import mpl_toolkits.axisartist.floating_axes as floating_axes

fig = plt.figure()

plot_extents = 0, 10, 0, 10
transform = Affine2D().rotate_deg(45)
helper = floating_axes.GridHelperCurveLinear(transform, plot_extents)
ax = floating_axes.FloatingSubplot(fig, 111, grid_helper=helper)

fig.add_subplot(ax)
plt.show()

在此处输入图片说明

对的,这是可能的。 但是您必须分别旋转每个标签。 因此,您可以尝试使用迭代:

from matplotlib import pyplot as plt
figure = plt.figure()
ax = figure.add_subplot(111)
t = figure.text(0.5,0.5,"some text")
t.set_rotation(90)
labels = ax.get_xticklabels()
for label in labels:
    label.set_rotation(45)
plt.show()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM