-1
我有一个关于matplotlib
Python模块的悬而未决的大问题。Python图形和轴对象
如果我创建了一个名为[Figure1]
人物,2个轴[Ax1, Ax2]
,和另一个数字[Figure2]
,是有一个函数或方法,让我到Ax1
对象从Figure1
出口,重新绘制到Figure2
对象?
我有一个关于matplotlib
Python模块的悬而未决的大问题。Python图形和轴对象
如果我创建了一个名为[Figure1]
人物,2个轴[Ax1, Ax2]
,和另一个数字[Figure2]
,是有一个函数或方法,让我到Ax1
对象从Figure1
出口,重新绘制到Figure2
对象?
在一般轴上绑定到一个数字。原因是,matplotlib通常会在后台执行一些操作,以使它们在图形中看起来不错。
还有some hacky ways around this,也this one,但一般的共识似乎是应避免试图复制轴。
另一方面,这不需要是问题或限制。
你总是可以定义一个函数,它不绘图,并用这个几个数字,像这样:
import matplotlib.pyplot as plt
def plot1(ax, **kwargs):
x = range(5)
y = [5,4,5,1,2]
ax.plot(x,y, c=kwargs.get("c", "r"))
ax.set_xlim((0,5))
ax.set_title(kwargs.get("title", "Some title"))
# do some more specific stuff with your axes
#create a figure
fig, (ax1, ax2) = plt.subplots(1,2)
# add the same plot to it twice
plot1(ax1)
plot1(ax2, c="b", title="Some other title")
plt.savefig(__file__+".png")
plt.close("all")
# add the same plot to a different figure
fig, ax1 = plt.subplots(1,1)
plot1(ax1)
plt.show()