子地块的轴变换似乎不适用于单个地块.
import numpy as np
data = np.random.randn(100)
from matplotlib import pyplot, transforms
# first of all, the base transformation of the data points is needed
base = pyplot.gca().transData
rot = transforms.Affine2D().rotate_deg(90)
# define transformed line
line = pyplot.plot(data, 'r--', transform= rot + base)
# or alternatively, use:
# line.set_transform(rot + base)
pyplot.show()
当将此方案用于子批次时,其工作不稳定.它适用于最后一个子图,如下所示.
import numpy as np
from matplotlib import pyplot, transforms
# Example data to display
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
##########################################
fig, axs = pyplot.subplots(2, 2)
axs[0, 0].plot(x, y)
axs[0, 0].set_title('Axis [0, 0]')
axs[0, 1].plot(x, y, 'tab:orange')
axs[0, 1].set_title('Axis [0, 1]')
axs[1, 0].plot(x, y, 'tab:green' )
axs[1, 0].set_title('Axis [1, 0]')
base = pyplot.gca().transData
rot = transforms.Affine2D().rotate_deg(90)
axs[1, 1].plot(x, -y, 'tab:red' , transform = rot + base )
axs[1, 1].set_title('Axis [1, 1]')
for ax in axs.flat:
ax.set(xlabel='x-label', ylabel='y-label')
# Hide x labels and tick labels for top plots and y ticks for right plots.
for ax in axs.flat:
ax.label_outer()
当对第三个子图(下面的示例)try 此操作时,现在显示跟踪.有人能帮忙解决这个问题吗.谢谢
# Example data to display
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
##########################################
fig, axs = pyplot.subplots(2, 2)
axs[0, 0].plot(x, y)
axs[0, 0].set_title('Axis [0, 0]')
axs[0, 1].plot(x, y, 'tab:orange')
axs[0, 1].set_title('Axis [0, 1]')
base = pyplot.gca().transData
rot = transforms.Affine2D().rotate_deg(90)
axs[1, 0].plot(x, y, 'tab:green' , transform = rot + base )
axs[1, 0].set_title('Axis [1, 0]')
axs[1, 1].plot(x, -y, 'tab:red' )
axs[1, 1].set_title('Axis [1, 1]')
for ax in axs.flat:
ax.set(xlabel='x-label', ylabel='y-label')
# Hide x labels and tick labels for top plots and y ticks for right plots.
for ax in axs.flat:
ax.label_outer()