gpt4 book ai didi

python - 如何旋转一个简单的 matplotlib 轴

转载 作者:太空狗 更新时间:2023-10-29 22:11:19 27 4
gpt4 key购买 nike

是否可以像 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()

enter image description here

关于python - 如何旋转一个简单的 matplotlib 轴,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21652631/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com