子地块的轴变换似乎不适用于单个地块.

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()

test 0

当将此方案用于子批次时,其工作不稳定.它适用于最后一个子图,如下所示.


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()

test 1

当对第三个子图(下面的示例)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()

test 2

推荐答案

当您在fig, axs = pyplot.subplots(2, 2)之后执行pyplot.gca()时,当前轴为axs[1,1],您可以通过pyplot.gca().get_gridspec()进行验证.这意味着您试图在axs[1,0]轴之外绘制.

所以你需要把base = pyplot.gca().transData改成

base = axs[1, 0].transData

enter image description here

Python相关问答推荐

如何确保Flask应用程序管理面板中的项目具有单击删除功能?

try 使用tensorFlow.keras.models时optree Import错误

解析讨论论坛只给我第一个用户 comments ,但没有给我其他用户回复

Numpy索引argsorted使用integer数组,同时保留排序顺序

Tkinter -控制调色板的位置

如果AST请求默认受csref保护,那么在Django中使用@ system_decorator(csref_protect)的目的是什么?

在编写要Excel的数据透视框架时修复标题行

是什么导致对Python脚本的jQuery Ajax调用引发500错误?

如何使用矩阵在sklearn中同时对每个列执行matthews_corrcoef?

Python中的负前瞻性regex遇到麻烦

多处理代码在while循环中不工作

在函数内部使用eval(),将函数的输入作为字符串的一部分

如何使用Python将工作表从一个Excel工作簿复制粘贴到另一个工作簿?

Python 约束无法解决n皇后之谜

数据抓取失败:寻求帮助

根据列值添加时区

如何指定列数据类型

lityter不让我输入左边的方括号,'

使用BeautifulSoup抓取所有链接

Geopandas未返回正确的缓冲区(单位:米)