erstellen wiederverwendbare Axessublot -Objekte in Matplotlib
Matplotlib liefert die Abbildung. Obwohl dies wirksam ist, kann es Szenarien geben, in denen das Erstellen von Axessublot -Objekten unabhängig von der Figur wünschenswert ist. Zum Beispiel:
def Plot (x, y, ax = none): Wenn Axe keine ist: ax = pt.gca () # Holen Sie sich die aktuelle Achseninstanz (Standard) Ax.Plot (x, y, 'go') ax.set_ylabel ('yabba dabba do!')
def plot(x, y, ax=None): if ax is None: ax = plt.gca() # Get the current axes instance (default) ax.plot(x, y, 'go') ax.set_ylabel('Yabba dabba do!')
# Erstellen Sie eine Figur mit zwei Sublots Fig1, (Ax1, Ax2) = Plt.SubPlots (nrows = 2) Diagramm (x, np.sin (x), ax1) # Verwenden Sie die erste Achseninstanz Diagramm (x, np.random.random (100), ax2) # Verwenden Sie die zweite Achseninstanz # Erstellen Sie eine neue Figur Fig2 = PLT.Figure () Diagramm (x, np.cos (x)) # Verwenden Sie die Achseninstanz der neuen Abbildung plt.show ()
# Create a figure with two subplots fig1, (ax1, ax2) = plt.subplots(nrows=2) plot(x, np.sin(x), ax1) # Use the first axes instance plot(x, np.random.random(100), ax2) # Use the second axes instance # Create a new figure fig2 = plt.figure() plot(x, np.cos(x)) # Use the new figure's axes instance plt.show()
matplotlib.pyplot als ptt # Erstellen Sie eine Achseninstanz ax = plt.gca () Ax.Plot (Bereich (10)) # Erstellen Sie eine neue Figur Fig2 = PLT.Figure () Fig. 22AXES.Append (AX) # Fügen Sie der neuen Figur die vorhandene Achseninstanz hinzu plt.show ()
import matplotlib.pyplot as plt # Create an axes instance ax = plt.gca() ax.plot(range(10)) # Create a new figure fig2 = plt.figure() fig2.axes.append(ax) # Add the existing axes instance to the new figure plt.show()
Haftungsausschluss: Alle bereitgestellten Ressourcen stammen teilweise aus dem Internet. Wenn eine Verletzung Ihres Urheberrechts oder anderer Rechte und Interessen vorliegt, erläutern Sie bitte die detaillierten Gründe und legen Sie einen Nachweis des Urheberrechts oder Ihrer Rechte und Interessen vor und senden Sie ihn dann an die E-Mail-Adresse: [email protected] Wir werden die Angelegenheit so schnell wie möglich für Sie erledigen.
Copyright© 2022 湘ICP备2022001581号-3