How to make hollow square marks with Matplotlib in Python?


To make hollow square marks with matplotlib, we can use marker 'ks', markerfacecolor='none', markersize=15, and markeredgecolor=red.

Steps

  • Creat x and y data points using numpy.

  • Create a figure or activate an existing figure, add an axes to the figure as part of a subplot arrangement.

  • Plot x and y data points using plot() method. To make hollow square marks, we can use marker "ks" and markerfacecolor="none", markersize="15" and markeredge color="red".

  • To display the figure, use show() method.

Example

import numpy as np
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
x = np.linspace(-2, 2, 10)
y = np.sin(x)
fig = plt.figure()
ax1 = fig.add_subplot(111)
ax1.plot(x, y, 'ks', markerfacecolor='none', ms=15, markeredgecolor='red')
plt.show()

Output

Updated on: 11-May-2021

4K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements