Javatpoint Logo
Javatpoint Logo

Scatter() plot matplotlib in Python

Matplotlib is a Python library that lets you make deterministic, animated, and engaging visualizations.

It is used to make plots in Python, such as bar charts, scatter plots, pie charts, histograms, line plots, 3-D plots, and many more. The matplotlib library contains the information about the scatter plot.

matplotlib.pyplot.scatter()

Scatter plots are utilized to see how different variables are related to each other. The dots on the plot shows how the variables are related. A scatter plot is made with the matplotlib library's scatter() method.

People often use scatter plots to show the relationship between two or more variables and how a change in one affects the other.

Syntax

Here's how to write code for the scatter() method:

matplotlib.pyplot.scatter (x_axis_value, y_axis_value, s = None, c = None, vmin = None, vmax = None, marker = None, cmap = None, alpha = None, linewidths = None, edgecolors = None)

The following are the syntax parameters for the scatter() method:

  • x_axis_value - An array containing x-axis data for scatter in the plot.
  • y_axis_value - an array with y-axis data.
  • s - it is the size of the marker (can be scalar or array of size equal to the size of the x-axis or y-axis)
  • c- the order of the colors of the markers
  • marker- marker style for scatter plot in the python.
  • cmap - cmap name for scatter plot in the python.
  • Linewidths - these are the size of the marker border for scatter in the plot.
  • edgecolor: the border color of a marker for scatter in the plot.
  • Alpha - blending value for scatter fucntion, between 0 and 1 (transparent to opaque)

All of the parameters except x-axis data and y-axis data are optional, and their default value is None.

Examples

Here are many examples of scatter plots in matplotlib with different parameters. We can see the different types of scatter plots with size, color, and other functions.

Example1: the following example shows a scatter plot using Python. We can see the plot values in the x and y-axis position.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example2: the following example shows a scatter plot using python. Here, we use the numpy package to compare two plots.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example3: the following example shows a scatter plot using python. Here, again we used the numpy package to compare two plots with different colors.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example4: the following example shows a scatter plot using python. Here, we use a different color for each plotted value. We can use the "c" to assign a color variable.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example5: the following example shows a scatter plot using Python. Here, we use a different color for each plotted value. We can use the "c" and "cmap" to assign color variables and color bars, respectively.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example6: the following example shows a scatter plot using Python. Here, we can use different sizes of the plot value.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example7: the following example shows a scatter plot using python. Here we use different sizes and opacity of the plot value.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example8: the following example shows a scatter plot using python. Here, we use a different color for each plotted value. We can use scatter plots with different colors, sizes, and opacity.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example9: the following example shows a scatter plot using python. Here, we use a different color for each plotted value. We can use random scatter plots with different colors, sizes, and opacity.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Example10: the following example shows a scatter plot using Python. Here, we use a different color for each plotted value. We can use scatter with different colors, sizes, edges, and line widths of the border.

Output

The following image shows a scatter plot with value in python.

Scatter() plot matplotlib in Python

Conclusion

The matplotlib displays plot figures using Python language. The scatter function in python shows a different type of figures in the graph. The figure shows different sizes, and opacities in python.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA