A scatter plot is often used to see the relationship between two variables. A line plot is often used when the data is distributed evenly along the horizontal axis. And a scatter plot is used to compare numeric values when the data is not distributed evenly along the x-axis. Usually, when for each value on the x-axis there are multiple values on the y-axis, we use a scatter plot.
We can use the seaborn.scatterplot() function to plot a scatterplot using the seaborn Python library. Let’s read the tips dataset. The dataset contains various information, such as the total bill amount, tip amount, etc. Let’s say we want to see the relationship between the total bill amount and the tip amount using a scatter plot. We can use the following Python code for that purpose:
import seaborn from matplotlib import pyplot df = seaborn.load_dataset("tips") seaborn.scatterplot(data=df, x="total_bill", y="tip") pyplot.savefig("seaborn-scatterplot.png") pyplot.close()
The resulting scatterplot will look like the following:






0 Comments