bugl
bugl
HomeLearnPatternsPathsSearchPremium
HomeLearnPatternsPaths
Learn/Python/Data Science and Scientific Python
Python•Data Science and Scientific Python

Matplotlib Markers

Markers

You can use the keyword argument marker to emphasize each point with a specified marker:

Example

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o')

plt.show()

Example

...

plt.plot(ypoints, marker = '*')

...

Format Strings fmt

You can also use the shortcut string notation parameter to specify the marker.

This parameter is also called fmt , and is written with this syntax:

Example

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, 'o:r')

plt.show()

The marker value can be anything from the Marker Reference above.

The line value can be one of the following:

Marker Size

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

Example

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20)

plt.show()

Marker Color

You can use the keyword argument markeredgecolor or the shorter mec to set the color of the edge of the markers:

Example

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mec = 'r')

plt.show()

You can use the keyword argument markerfacecolor or the shorter mfc to set the color inside the edge of the markers:

Example

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mfc = 'r')

plt.show()

Use both the mec and mfc arguments to color the entire marker:

Example

import matplotlib.pyplot as plt

import numpy as np

ypoints = np.array([3, 8, 1, 10])

plt.plot(ypoints, marker = 'o', ms = 20, mec = 'r', mfc = 'r')

plt.show()

You can also use Hexadecimal color values :

Example

...

plt.plot(ypoints, marker = 'o', ms = 20, mec = '#4CAF50', mfc = '#4CAF50')

...

Or any of the 140 supported color names .

Example

...

plt.plot(ypoints, marker = 'o', ms = 20, mec = 'hotpink', mfc = 'hotpink')

...

Previous

Machine Learning - Percentiles

Next

Machine Learning - Data Distribution

This chapter

Overview
38

Lessons

159m

Read time

1. NumPy Tutorial2. Matplotlib Tutorial3. Machine Learning4. Pandas Tutorial5. Matplotlib Getting Started6. Machine Learning - Mean Median Mode7. Matplotlib Pyplot8. Machine Learning - Standard Deviation9. Matplotlib Plotting10. Machine Learning - Percentiles11. Matplotlib Markers12. Machine Learning - Data Distribution13. Matplotlib Line14. Machine Learning - Normal Data Distribution15. Matplotlib Labels and Title16. Machine Learning - Scatter Plot17. Matplotlib Adding Grid Lines18. Machine Learning - Linear Regression19. Matplotlib Subplot20. Machine Learning - Polynomial Regression21. Matplotlib Scatter22. Machine Learning - Multiple Regression23. Matplotlib Bars24. Machine Learning - Scale25. Matplotlib Histograms26. Machine Learning - Train/Test27. Matplotlib Pie Charts28. Machine Learning - Decision Tree29. Machine Learning - Confusion Matrix30. Machine Learning - Hierarchical Clustering31. Machine Learning - Logistic Regression32. Machine Learning - Grid Search33. Preprocessing - Categorical Data34. Machine Learning - K-means35. Machine Learning - Bootstrap Aggregation (Bagging)36. Machine Learning - Cross Validation37. Machine Learning - AUC - ROC Curve38. Machine Learning - K-nearest neighbors (KNN)

On this page

MarkersFormat Strings fmtMarker SizeMarker Color