簡體   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