How to use figure function(python, matplotlib). Draw multiple graphs



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0


Release date:2024/4/6         

In Japanese


■Figure function description

Draw multiple graphs.

■Concrete example
The following must be written in common for each specific example.

import matplotlib.pyplot as plt
import numpy as np # Defined to use the arange function

Example (1)
To display it in one window, use the following.

x=np.arange(10)
y1=x*2
y2=x*x

plt.figure()

plt.subplot(2,1,1) # Defined first in 2 rows and 1 column graph
plt.plot(x, y1)

plt.subplot(2,1,2) # Defined second in 2 rows and 1 column graph
plt.plot(x, y2)

plt.show()



Example (2)
To display in multiple windows, use the following.

x=np.arange(10)
y1=x*2
y2=x*x

plt.figure()
plt.plot(x, y1)

plt.figure()
plt.plot(x, y2)

plt.show()











List of related articles



Python
library
pip

MeCab

numpy
digitize

mgrid

pad

polyfit

prod

shape

matplotlib
pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

scipy
interpolate
tkinter
postscript

image display

frame, grid

other
linear interpolation

OpenAI gym
CartPole-v0