Wie kann ich Grundstücke in matplotlib wiederverwenden?
Ich möchte Diagramme auf 4 Achsen erstellen, die ersten drei einzelnen Diagramme auf jeder Achse und die letzten drei Diagramme auf den letzten Achsen. Hier ist der Code:
<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>
Das resultierende Bild ist:
Gibt es eine Möglichkeit, Diagramme zuerst zu definieren und sie dann zu Achsen hinzuzufügen und sie dann zu zeichnen? Hier ist die Logik, die ich im Sinn hatte:
<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>
Zeichnen Sie nun Linie1 auf Achse1, Linie2 auf Achse2, Linie3 auf Achse3 und Linie4 auf Achse4.