How to Connect Scatterplot Points With Line in Matplotlib? (original) (raw)

Last Updated : 23 Dec, 2020

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:

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:

Similar Reads

Introduction







Multiple Plots







Working with Legends












Line Chart







Bar Plot









Histogram






Scatter Plot






Pie Chart




3D Plots










Working with Images