Introduction
Connected scatterplots are just a mix between scatterplots and linecharts. It can be made using the plot() function of matplotlib with the possible parameters:
- x: The horizontal coordinates of the data points.
- y: The vertical coordinates of the data points.
- linestyle: Line style, also abbreviated as ls. A list of available styles and how to customize them can be found here. Some of the most popular are "-" for a solid line, "--" for a dashed line, and ":" for a dotted line.
- marker: Marker style. A complete list of available markers can be found here. Some of the most popular are "o" for a circle, "." for a point, "^" for a triangle, etc.
If you want to customize them, just check the scatter and line sections of the website!
Libraries & Data
By default, plt.plot() generates a solid line plot. This function can also be used to obtain both a scatterplot and a lineplot at once by passing both the linestyle and the marker type.
Default grouped connected scatterplot
Notice the legend generated automatically combines both lines and markers. This legend also reflects any customization we may apply.
Customize lines and markers
Legend tweaks
If you want to have only either the line or the dot in the legend you can combine plt.scatter() and plt.plot() giving the label to the one you want to include in the legend. For example:
Constructing the connected scatterplot component by component also gives us more flexibility to customize our plot. For example, it is possible to use different colors for the markers by passing a list of colors to the color argument in plt.scatter().
More customization
We would have obtained an error if we had passed color=["red", "black"] * 5 to the plt.plot() function.