DEV Community

TechPlygrnd
TechPlygrnd

Posted on

Matplotlib Tutorial #5: Plot Marker Customization

In this blog, I will show you how to make your plot more interesting with plot marker customization.


Marker Style

In Matplotlib, the marker refers to the points that are being plotted in the plot. The default plot method does not include a marker in the plot, therefore the output will look like this

import matplotlib.pyplot as plt
import numpy as np

xpoints = np.array([0, 1, 2, 3, 5, 6])
ypoints = np.array([0, 1, 2, 3, 5, 6])

plt.plot(xpoints, ypoints)
plt.show()
Enter fullscreen mode Exit fullscreen mode

That produces the following output

Plot 1

By passing optional argument marker with certain value, you can make mark each of your point like the following

import matplotlib.pyplot as plt
import numpy as np

xpoints = np.array([0, 1, 2, 3, 5, 6])
ypoints = np.array([0, 1, 2, 3, 5, 6])

plt.plot(xpoints, ypoints, marker='o')
plt.show()
Enter fullscreen mode Exit fullscreen mode

That produces the following output

Plot 2

As I mention previously, optional argument marker will hold a certain value, and you can reference that value from here

Marker style reference

Marker Size

You can use the keyword argument markersize or the shorter version, ms to set the size of the markers

import matplotlib.pyplot as plt
import numpy as np

xpoints = np.array([0, 1, 2, 3, 5, 6])
ypoints = np.array([0, 1, 2, 3, 5, 6])

plt.plot(xpoints, ypoints, marker='o', markersize=15)
plt.show()
Enter fullscreen mode Exit fullscreen mode

Which produces the following output

Plot 3


There you go, that is how you can customize your marker in plot. Thank you for reading this blog and have a nice day!

Top comments (0)