Monday 28 August 2023

How to Change the Marker Edge Color in Matplotlib

Using 'markeredgecolor' parameter of plot method, we can specify the color of the edge of a marker.

Example

plt.plot(x1, y1, marker='o', markeredgecolor='red', markeredgewidth=2)

 

You can even use short notation 'mec' to represent markeredgecolor and 'mew' to represent markeredgewidth.

        

marker_edge_color.py

 

import matplotlib.pyplot as plt

# Sample data
x1 = [5, 10, 15, 20, 25]
y1 = [20, 40, 60, 80, 100]

plt.plot(x1, y1, marker='o', mec='red', mew=2)

# To display the legend on the plot
plt.legend()

plt.show()

Output



 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment