How to create scatter plot using Python’s seaborn library?
To plot a scatter plot using seaborn, follow these steps:
- Import the necessary Python libraries.
import seaborn as sns
import matplotlib.pyplot as plt
- Prepare the dataset:
data = sns.load_dataset('tips')
- Create a scatter plot.
sns.scatterplot(x='total_bill', y='tip', data=data)
- 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.