Prerequisite: Scatterplot using Seaborn in Python
Scatterplot can be used with several semantic groupings which can help to understand well in a graph. They can plot two-dimensional graphics that can be enhanced by mapping up to three additional variables while using the semantics of hue, size, and style parameters. And matplotlib is very efficient for making 2D plots from data in arrays. In this article, we are going to see how to connect scatter plot points with lines in matplotlib.
Approach:
- Import module.
- Determined X and Y coordinate for plot scatter plot points.
- Plot scatterplot.
- Plot matplotlib.pyplot with the same X and Y coordinate.
Below is the implementation:
Example 1:
Python3
import numpy as np
import matplotlib.pyplot as plt
x = [ 0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
y = [ 6.2 , - 8.4 , 8.5 , 9.2 , - 6.3 ]
plt.title( "Connected Scatterplot points with lines" )
plt.scatter(x, y)
plt.plot(x, y)
|
Output:

Example 2:
Python3
import numpy as np
import matplotlib.pyplot as plt
x = [ 1 , 2 , 3 ]
y = [ 1 , 2 , 3 ]
plt.title( "Connected Scatterplot points with lines" )
plt.scatter(x, y)
plt.plot(x, y)
|
Output:

Example 3:
We can also connect scatter plot points with lines without using seaborn.scatterplot. We will use only pyplot to connect the scatter points with lines.
Python3
import numpy as np
import matplotlib.pyplot as plt
x = [ 0.1 , 0.2 , 0.3 , 0.4 , 0.5 ]
y = [ 6.2 , - 8.4 , 8.5 , 9.2 , - 6.3 ]
plt.title( "Connected Scatterplot points with line" )
plt.plot(x, y, marker = "*" )
plt.show()
|
Output:

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape,
GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out -
check it out now!
Last Updated :
23 Dec, 2020
Like Article
Save Article