How to create scatter plot using Python’s seaborn library?

To plot a scatter plot using seaborn, follow these steps:

  1. Import the necessary Python libraries.
import seaborn as sns
import matplotlib.pyplot as plt
  1. Prepare the dataset:
data = sns.load_dataset('tips')
  1. Create a scatter plot.
sns.scatterplot(x='total_bill', y='tip', data=data)
  1. Display graphics:
plt.show()

The complete code is shown below:

import seaborn as sns
import matplotlib.pyplot as plt

data = sns.load_dataset('tips')

sns.scatterplot(x='total_bill', y='tip', data=data)

plt.show()

This will create a scatter plot with ‘total_bill’ on the x-axis and ‘tip’ on the y-axis.

bannerAds