Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
How to create a Scatter Plot with several colors in Matplotlib?
Next article icon

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 moduleimportnumpyasnpimportmatplotlib.pyplotasplt# initialize x and y coordinatesx=[0.1,0.2,0.3,0.4,0.5]y=[6.2,-8.4,8.5,9.2,-6.3]# set the title of a plotplt.title("Connected Scatterplot points with lines")# plot scatter plot with x and y dataplt.scatter(x,y)# plot with x and y dataplt.plot(x,y)

Output:

Example 2:

Python3
# import moduleimportnumpyasnpimportmatplotlib.pyplotasplt# initialize x and y coordinatesx=[1,2,3]y=[1,2,3]# set the title of a plotplt.title("Connected Scatterplot points with lines")# plotting scatter and pyplotplt.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 moduleimportnumpyasnpimportmatplotlib.pyplotasplt# initialize x and y coordinatesx=[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:


Improve
Practice Tags :

Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp