Scatter Plots - ( Basic Matplotlib )
Heading h2
Syntax
import matplotlib.pyplot as plt
plt.scatter(x, y, s=None, c=None, marker=None, cmap=None, norm=None, vmin=None, vmax=None, alpha=None, linewidths=None, edgecolors=None)
Example
import matplotlib.pyplot as plt
x = [1, 2, 3, 4, 5]
y = [2, 4, 1, 5, 3]
plt.scatter(x, y)
plt.title('Example Scatter Plot')
plt.xlabel('X-axis')
plt.ylabel('Y-axis')
plt.show()
Output
The output is a scatter plot displayed in a separate window, with the given data points plotted as dots.
Explanation
A scatter plot is a graph that shows the relationship between two variables by displaying the individual data points as dots. It is a useful visualization tool for understanding the distribution of data and identifying any patterns or trends.
Matplotlib provides the scatter()
method for creating scatter plots. It takes in two arrays or lists of data points for the x and y axes, and any additional parameters for customizing the plot such as color, marker, size, etc.
In the above example, we create a simple scatter plot using the scatter()
method with the given x and y data points. We customize the plot with a title, x-axis and y-axis labels, and display the plot using the show()
method.
Use
Scatter plots are useful for visualizing the relationship between two variables and identifying patterns or trends in the data. They are commonly used in data analysis, machine learning, and scientific research.
Important Points
- A scatter plot is a graph that displays individual data points as dots
- Matplotlib provides the
scatter()
method for creating scatter plots - The method takes in two arrays or lists of data points for the x and y axes, and additional parameters for customizing the plot
- Scatter plots are useful for visualizing relationships between two variables, and identifying patterns or trends in the data
Summary
In conclusion, scatter plots are a useful visualization tool for understanding the distribution of data and identifying any patterns or trends. Matplotlib provides the scatter()
method for creating scatter plots with customizations such as color, size, and marker shape. Scatter plots are commonly used in data analysis, machine learning, and scientific research.