Data Visualisation using Matplotlib for beginners (Part 2)

In the previous blog, we saw how to plot simple line plots and do some formatting to make them look attractive. In case you haven't checked it out…check it now!

After the line plots let’s work with Scatter Plots.

Scatter Plots

We will use the same data as we used for the line plot in the previous blog.

1. Make a simple scatter plot

We have three arrays x,y1, and y2.

plt.scatter(x,y1)plt.scatter(x,y2)plt.show()

2. Put Titles

The process remains the same as we did for the line plot

plt.xlabel(“Time”)plt.ylabel(“Speed”)plt.title(“Speed v/s Time Curve”)

3. Change the symbols

Till now you were getting dots on your plot. You can change this symbol using the marker parameter.

We can use symbols like stars and triangles.

plt.scatter(x,y1, color=”red”, label=”A”, marker=”*”)plt.scatter(x,y2, color=”green”, label=”B”)plt.legend()plt.xlabel(“Time”)plt.ylabel(“Speed”)plt.title(“Speed v/s Time Scatter Plot”)plt.show
plt.scatter(x,y1, color=”red”, label=”A”, marker=”^”)plt.scatter(x,y2, color=”green”, label=”B”)plt.legend()plt.xlabel(“Time”)plt.ylabel(“Speed”)plt.title(“Speed v/s Time Scatter Plot”)plt.show

4. Adjust the size of any plot

We can adjust the size of any plot with help of plt. figure(figsize=(2,2)). You can give any dimensions in place of (2,2), and see the output.

plt.figure(figsize=(2,2))plt.scatter(x,y1, color=”red”, label=”A”, marker=”^”)plt.scatter(x,y2, color=”green”, label=”B”)plt.legend()plt.xlabel(“Time”)plt.ylabel(“Speed”)plt.title(“Speed v/s Time Scatter Plot”)plt.show
plt.figure(figsize=(10,5))
plt.figure(figsize=(8,2))

You can choose the best fit as per your need. Keep experimenting with more parameters.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store