The Wayback Machine - https://web.archive.org/web/20220923061652/https://www.geeksforgeeks.org/how-to-plot-two-dotted-lines-and-set-marker-using-matplotlib/
Skip to content
Related Articles

Related Articles

How to plot two dotted lines and set marker using Matplotlib?

View Discussion
Improve Article
Save Article
  • Last Updated : 28 Nov, 2021
View Discussion
Improve Article
Save Article

In this article, we will plot two dotted lines and set markers using various functions of the matplotlib package in the python programming language.

We can use the pyplot.plot along with the linestyle parameter function to draw the dotted line. 

matplotlib.pyplot.plot(array1,array2,linestyle='dotted')

Note: 

  • To set the marker, we have to use the label parameter.
  • To display the label we have to use the legend method.

Example 1:

In this example, we created four lists(data points) in which two lists. First, we are plotting the first line with two data points with dotted line style by mentioning label and then plotting the second line with two data points with dotted line style by mentioning label and displaying the label by using the legend() function.

Python3




# import matplotlib
import matplotlib.pyplot as plt
  
# create array 1 for first line
firstarray1 = [1, 3, 5, 7, 9, 11, 23, 45, 67, 89]
  
# create array 2 for first line
secondarray1 = [23, 45, 2, 56, 78, 11, 22, 33, 44, 45]
  
# create array 1 for second line
firstarray2 = [2, 4, 6, 8, 10, 11, 22, 33, 44]
  
# create array 2 for second line
secondarray2 = [11, 34, 56, 43, 56, 11, 22, 33, 44]
  
# plot the line1
plt.plot(firstarray1, secondarray1, linestyle='dotted',
         label='line1', linewidth=6, color="pink")
  
# plot the line2
plt.plot(firstarray2, secondarray2, linestyle='dotted',
         label='line2', linewidth=8)
  
plt.legend()
  
# display
plt.show()

Output:

Example 2:

In this example, we created four lists(data points then plotting the first line with one sin function from the NumPy module with dotted line style by mentioning label and then plotting the second line with cos function from the NumPy module with two data points with dotted line style by mentioning label.

Python3




# import matplotlib
import matplotlib.pyplot as plt
  
# import numpy module
import numpy
  
# create array 1 for first line
firstarray1 = [1, 3, 5, 7, 9, 11, 13, 15, 17]
  
# create array 2 for first line
secondarray1 = [23, 45, 2, 56, 78, 45, 67, 23, 11]
  
# create array 1 for second line
firstarray2 = [2, 4, 6, 8, 10, 45, 32, 11, 78]
  
# create array 2 for second line
secondarray2 = [11, 34, 56, 43, 56]
  
# plot the line1 with sin function
plt.plot(firstarray1, numpy.sin(firstarray1),
         linestyle='dotted', label='line1', 
         linewidth=6, color="green")
  
# plot the line2 with cos function
plt.plot(firstarray2, numpy.cos(secondarray1),
         linestyle='dotted', label='line2', linewidth=8)
  
plt.legend()
  
# display
plt.show()

Output:


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!