A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://python-graph-gallery.com/40-basic-scatterplot-seaborn/ below:

Website Navigation


Basic Scatterplot with Seaborn

Libraries

First, we need to load a few libraries:

import seaborn as sns
import matplotlib.pyplot as plt
import pandas as pd
Dataset

Since scatter plot are made for visualizing relationships between two numerical variables, we need a dataset that contains at least two numerical columns.

Here, we will use the iris dataset that we load directly from the gallery:

path = 'https://raw.githubusercontent.com/holtzy/The-Python-Graph-Gallery/master/static/data/iris.csv'
df = pd.read_csv(path)
df.head()
sepal_length sepal_width petal_length petal_width species 0 5.1 3.5 1.4 0.2 setosa 1 4.9 3.0 1.4 0.2 setosa 2 4.7 3.2 1.3 0.2 setosa 3 4.6 3.1 1.5 0.2 setosa 4 5.0 3.6 1.4 0.2 setosa Scatter plot

A scatterplot can be made using scatterplot() function of seaborn library. An example dataset from seaborn repository, iris dataset, is used in the example. The plot shows the relationship between sepal lenght and width of plants. In order to show the most basic utilization of this function, the following parameters should be provided:

sns.scatterplot(x=df["sepal_length"], y=df["sepal_width"])
plt.show()

Alternatively: you can use the following syntax:

sns.scatterplot(data=df, x="sepal_length", y="sepal_width")
plt.show()
Customize the scatter plot

The scatterplot() function accepts the following arguments (among others):

You can find all the available colors here.

sns.scatterplot(
    x=df["sepal_length"],
    y=df["sepal_width"],
    color="red",
    edgecolor="darkred",
    alpha=0.6,
    s=200
)
plt.show()

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4