Related Articles

# How to Add Markers to a Graph Plot in Matplotlib with Python?

• Last Updated : 16 Nov, 2020

Prerequisite: Matplotlib

In this article we will learn how to add markers to a Graph Plot in Matplotlib with Python. For that just see some concepts that we will use in our work.

Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.

To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course. And to begin with your Machine Learning Journey, join the Machine Learning - Basic Level Course

• Matplotlib : Matplotlib is a tremendous visualization library in Python for 2D plots of arrays. Matplotlib may be a multi-platform data visualization library built on NumPy arrays and designed to figure with the broader SciPy stack. It was introduced by John Hunter within the year 2002.
• Graph Plot : A plot is a graphical technique for representing a data set, usually as a graph showing the relationship between two or more variables.
• Markers : The markers are shown in graph with different shapes and color to modify the meaning of graph.

### Approach

To generate a graph with a modified marker style, following steps need to be followed:

1. Import packages
2. Import or create some data
3. Draw a graph plot.
4. Set the marker by using marker feature.

Example 1:

## Python3

 `# importing packages``import` `matplotlib.pyplot as plt`` ` `# plot with marker``plt.plot([``2``, ``8``, ``7``, ``4``, ``7``, ``6``, ``2``, ``5``, ``9``], marker``=``'D'``)``plt.show()`

Output : Example 2 :

## Python3

 `# importing packages``import` `matplotlib.pyplot as plt`` ` `# create data``t ``=` `np.arange(``0.``, ``5.``, ``0.2``)`` ` `# plot with marker``plt.plot(t, t, ``'r--'``, t, t``*``*``2``, ``'bs'``, t, t``*``*``3``, ``'g^'``)``plt.show()`

Output : Example 3 :

## Python3

 `# importing packages``import` `matplotlib.pyplot as plt``import` `numpy as np`` ` `# create data``x_values ``=` `np.linspace(``0``, ``10``, ``20``)``y_values ``=` `np.sin(x_values)``markers ``=` `[``'>'``, ``'+'``, ``'.'``, ``','``, ``'o'``, ``'v'``, ``'x'``, ``'X'``, ``'D'``, ``'|'``]`` ` `# apply markers``for` `i ``in` `range``(``20``):``    ``plt.plot(x_values, y_values ``+` `i``*``0.2``, markers[i ``%` `10``])``plt.show()`

Output : My Personal Notes arrow_drop_up