How to use matplotlib's "scatter" function. python



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding


Release date:2023/2/22         

In Japanese


■Description of the scatter function

Draw a scatterplot.

■Specific example using scatter function

import numpy as np
import matplotlib.pyplot as plt

x = np.random.rand(10) #Generate an array of random numbers
y = np.random.rand(10)

plt.scatter(x, y) #Draw a scatterplot
plt.show()


The results are as follows.


■Difference between "scatter" and "plot"

A matplotlib function similar to scatter is "plot". plot is a graph drawing function that can also draw scatterplots. Change the above program as follows.

plt.scatter(x, y) #change as follows
↓↓↓
plt.plot(x, y, "o")


You should be able to draw a scatterplot similar to the one above. The advantage of scatter is that you can make more detailed settings than "plot". For example:

"s":size
"c":color
"alpha":transmittance
"edgecolors":edge color
"marker":marker shape


plt.scatter(x, y, s=300, c="red", alpha=0.5,edgecolors="blue", marker="^")


The results are as follows.










List of related articles



Python
library
pip

MeCab

Common
class

pickle

read/readline

numpy
asfarray

digitize

expit

linalg.solve

meshgrid

mgrid

ndmin

pad

poly1d

polyfit

prod

shape

matplotlib
figure

pcolormesh

scatter

pytorch
BCELoss, MSELoss

device

Embedding

TensorDataset, Dataloader

RNN, LSTM
scikit-learn
SVC

GaussianNB

scipy
interpolate
tkinter
postscript

image display

frame, grid

Crop Image

other
linear interpolation

Hysteresis switch

Square/Triangle wave

OpenAI gym
CartPole-v0

By purpose
1 of K Coding