add_subplot()--matplotlib

Neu gepostet von: add_subplot()--matplotlib_Morning Glory Master's Blog-CSDN Blog

1. Funktion add_subplot()

1.1 Funktionen

Add an Axes to the figure as part of a subplot arrangement.
  • 1

Fügen Sie der Leinwand Achsen hinzu

1.2 Funktionssyntax:

add_subplot(nrows, ncols, index, **kwargs)
  • 1

1.3 Funktionsparameter

1.3.1 Nrows, Ncols, Index

Die Position der Nebenhandlung wird durch die folgenden drei Parameter bestimmt:

Three integers (nrows, ncols, index). 
The subplot will take the index position on a grid with nrows rows and ncols columns. 
index starts at 1 in the upper left corner and increases to the right. 
index can also be a two-tuple specifying the (first, last) indices (1-based, and including last) of the subplot, 
e.g., fig.add_subplot(3, 1, (1, 2)) makes a subplot that spans the upper 2/3 of the figure. 
  • 1
  • 2
  • 3
  • 4
  • 5

Die Parameter nrows und ncols bestimmen, wie viele Teile die Leinwand in nrows*ncols unterteilt wird. Der Indexindex beginnt in der oberen linken Ecke und erhöht sich nach rechts.
Der Index kann auch als binäres Array angegeben werden, was angibt, dass das Diagramm die Position vom ersten Parameter des Index bis zum zweiten Parameter einnimmt.
Beispiel: fig.add_subplot(3, 1, (1, 2)), was angibt, dass die Position, die die Nebenhandlung einnimmt, die ersten beiden Positionen nach der Aufteilung der Leinwand in drei gleiche Teile sind.

import matplotlib.pyplot as plt
import numpy as np

x1 = np.linspace(-2 * np.pi, 2 * np.pi, 500)
y1 = np.sin(x1)

plt.subplot(1, 3, 1)
plt.plot(x1, y1)

plt.show()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

Fügen Sie hier eine Bildbeschreibung ein

 

Guess you like

Origin blog.csdn.net/u010087338/article/details/131978389