Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 图add#u subplot()*transform*不';不行?_Python_Matplotlib - Fatal编程技术网

Python 图add#u subplot()*transform*不';不行?

Python 图add#u subplot()*transform*不';不行?,python,matplotlib,Python,Matplotlib,关于这篇文章,我正在研究这个解决方案,但由于某些原因,转换被忽略了 我搞错了?还是有虫子 import matplotlib.pyplot as plt import numpy as np axes = [] x = np.linspace(-np.pi,np.pi) fig = plt.figure(figsize=(10,10)) subpos = (0,0.6) for i in range(4): axes.append(fig.add_subplot(2,2,i)) fo

关于这篇文章,我正在研究这个解决方案,但由于某些原因,转换被忽略了

我搞错了?还是有虫子

import matplotlib.pyplot as plt
import numpy as np

axes = []
x = np.linspace(-np.pi,np.pi)
fig = plt.figure(figsize=(10,10))
subpos = (0,0.6)

for i in range(4):
   axes.append(fig.add_subplot(2,2,i))

for axis in axes:
    axis.set_xlim(-np.pi,np.pi)
    axis.set_ylim(-1,3)
    axis.plot(x,np.sin(x))
    fig.add_axes([0.5,0.5,0.1,0.1],transform=axis.transAxes)

plt.show()
屈服


主要问题是使用一些方法在子批次中模拟plt.axes()。其思想是在网格的每个子地块内创建小的子地块。看看Ok,但这不是我问题的答案。。。我知道如何使用与您类似的方法进行转换,但我不明白为什么fig.add_Axis()支持变换karg,但它不起作用。
变换
kwarg——最多——将点从一个坐标系转换为另一个坐标系。高度和宽度是比率,而不是点,因此不能使用
转换
kwarg单独将
[左、下、宽、高]
列表从相对于轴的角度转换为相对于图形的适当列表。是的,但是转换比率在框中是微不足道的。所以,我不明白为什么变换是一堆叠加轴。无论如何,它是有用的。谢谢我有另一篇文章来讨论这个问题,非常类似于你的解决方案。
import matplotlib.pyplot as plt
import numpy as np

def axis_to_fig(axis):
    fig = axis.figure
    def transform(coord):
        return fig.transFigure.inverted().transform(
            axis.transAxes.transform(coord))
    return transform

def add_sub_axes(axis, rect):
    fig = axis.figure
    left, bottom, width, height = rect
    trans = axis_to_fig(axis)
    figleft, figbottom = trans((left, bottom))
    figwidth, figheight = trans([width,height]) - trans([0,0])
    return fig.add_axes([figleft, figbottom, figwidth, figheight])

x = np.linspace(-np.pi,np.pi)
fig, axes = plt.subplots(nrows=2, ncols=2, figsize=(10,10))

for axis in axes.ravel():
    axis.set_xlim(-np.pi, np.pi)
    axis.set_ylim(-1, 3)
    axis.plot(x, np.sin(x))
    subaxis = add_sub_axes(axis, [0.2, 0.6, 0.3, 0.3])
    subaxis.plot(x, np.cos(x))

plt.show()