DEV Community

TechPlygrnd
TechPlygrnd

Posted on

1 1

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!

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay