Scatter plots are a type of chart used to visualize the relationship between two variables. They display the data as a collection of points, where each point represents a pair of values for the two variables. Scatter plots are commonly used to identify patterns, trends, and outliers in the data.
In Python, you can create scatter plots using various libraries such as Matplotlib, Seaborn, and Plotly. Here's an example using Matplotlib:
import matplotlib.pyplot as pltimport numpy as np# Generate some random datax = np.random.randn(100)y = np.random.randn(100)# Create a scatter plotplt.scatter(x, y)# Set the title and axis labelsplt.title('Scatter Plot of Random Data')plt.xlabel('X')plt.ylabel('Y')# Show the plotplt.show() |
In this example, we generate 100 random values for the x-axis and y-axis using NumPy. We create a scatter plot using plt.scatter(), where the first argument is the x-axis data and the second argument is the y-axis data. We then set the title and axis labels using plt.title(), plt.xlabel(), and plt.ylabel(), and display the plot using plt.show().
You can also customize the appearance of the scatter plot by specifying the color, size, and other options. For example, to change the color of the points to red, add color='red' to the plt.scatter() call. To change the size of the points to 50, add s=50.