回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我想在四个轴上画出图,每个轴上的前三个单独的图,最后三个都在最后一个轴上。
代码如下:</p>
<pre><code>from numpy import *
from matplotlib.pyplot import *
fig=figure()
data=arange(0,10,0.01)
ax1=fig.add_subplot(2,2,1)
ax2=fig.add_subplot(2,2,2)
ax3=fig.add_subplot(2,2,3)
ax4=fig.add_subplot(2,2,4)
line1=ax1.plot(data,data)
line2=ax2.plot(data, data**2/10, ls='--', color='green')
line3=ax3.plot(data, np.sin(data), color='red')
#could I somehow use previous plots, instead recreating them all?
line4=ax4.plot(data,data)
line4=ax4.plot(data, data**2/10, ls='--', color='green')
line4=ax4.plot(data, np.sin(data), color='red')
show()
</code></pre>
<p>结果图片是:<br/><img src="https://i.stack.imgur.com/3vWwg.png" alt="enter image description here"/><br/>
有没有办法先定义绘图,然后将其添加到轴上,然后再绘图?以下是我的逻辑:</p>
<pre><code>#this is just an example, implementation can be different
line1=plot(data, data)
line2=plot(data, data**2/10, ls='--', color='green')
line3=plot(data, np.sin(data), color='red')
line4=[line1, line2, line3]
</code></pre>
<p>现在打印ax1上的第1行、ax2上的第2行、ax3上的第3行和ax4上的第4行。</p>