Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
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
Create x and y data points using NumPy.
Create a figure and 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, use marker "ks",markerfacecolor="none",markersize=15, andmarkeredgecolor="red".Display the figure using
show()method.
Example
Here's how to create hollow square markers ?
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()
Marker Parameters
The key parameters for creating hollow squares are ?
| Parameter | Value | Purpose |
|---|---|---|
'ks' |
Square marker | Defines the marker shape and color |
markerfacecolor |
'none' | Makes the marker hollow |
markersize or ms
|
15 | Controls the size of the marker |
markeredgecolor |
'red' | Sets the edge/border color |
Customization Options
You can customize the hollow squares further ?
import numpy as np
from matplotlib import pyplot as plt
x = np.linspace(0, 10, 8)
y = x**0.5
plt.figure(figsize=(8, 4))
plt.plot(x, y, 'ks', markerfacecolor='none', ms=20,
markeredgecolor='blue', markeredgewidth=2)
plt.title('Customized Hollow Square Markers')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.grid(True, alpha=0.3)
plt.show()
Conclusion
Use marker 'ks' with markerfacecolor='none' to create hollow square markers. Adjust markersize and markeredgecolor to customize appearance and visibility.
