Libraries & Dataset
Let's start by loading the necessary libraries and create a dataset
- matplotlib: for displaying the plot
- pandas: for data manipulation
numpy: for data generation
# libraries
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
# Create a dataset:
df = pd.DataFrame({
'x_values': range(1, 101),
'y_values': np.random.randn(100)*15+range(1, 101)
})
df.head()| x_values | y_values | |
|---|---|---|
| 0 | 1 | 16.036968 |
| 1 | 2 | -11.666240 |
| 2 | 3 | 8.503309 |
| 3 | 4 | 7.816552 |
| 4 | 5 | -0.893881 |
Most simple scatter plot
This is a basic scatterplot example made with the scatter() function of Matplotlib. These arguments are passed to the function:
x: column name to be used for the x axisy: column name to be used for the y axisdata: the dataset to be usedlinestyle: style of the lines between each pointmarker: marker style of the points
fig, ax = plt.subplots()
ax.scatter(
'x_values', 'y_values',
data=df,
marker='o'
)
plt.show()Going further
This post explains how to create a scatter plot with Matplotlib.
You might be interested in how to custom markers in scatter plots and how to link title and markers in scatter plots.






