如何旋转一个简单的 matplotlib 轴 [英] How to rotate a simple matplotlib Axes
问题描述
是否可以像 matplotlib.text.Text 一样旋转 matplotlib.axes.Axes
is it possible to rotate matplotlib.axes.Axes as it is for matplotlib.text.Text
# 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 将围绕其坐标轴以角度值旋转文本.有没有办法对轴实例执行相同的操作?
a simple set_rotation on a text instance will rotate the text by the angle value about its coordinates axes. Is there any way to do to same for the axes instance ?
推荐答案
您要问如何旋转整个轴(而不仅仅是文本)吗?
Are you asking how to rotate the entire axes (and not just the text)?
如果是这样,是的,这是可能的,但是您必须事先了解情节的范围.
If so, yes, it's possible, but you have to know the extents of the plot beforehand.
您必须使用 axisartist
,它允许像这样的更复杂的关系,但有点复杂,不适合交互式可视化.如果尝试缩放等,将会遇到问题.
You'll have to use axisartist
, which allows more complex relationships like this, but is a bit more complex and not meant for interactive visualization. If you try to zoom, etc, you'll run into problems.
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()
这篇关于如何旋转一个简单的 matplotlib 轴的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!