ben121
ben121

Reputation: 897

Plotting single data point using seaborn

I am using seaborn to create a boxplot. But how would I add a line or a single point to show a single data value on the chart. For instance how would i go about plotting the value 3.5 on the below chart.

import seaborn as sns
import matplotlib.pyplot as plt

df1 = [2.5, 2.5, 2, 3, 4, 3.5]
sns.set_style("whitegrid")
fig, ax = plt.subplots(figsize=(8,8))
plot1 = sns.boxplot(ax=ax, x=df1, linewidth=5)

Upvotes: 5

Views: 12148

Answers (2)

sacuL
sacuL

Reputation: 51335

You can achieve the same effect using plt.scatter. Personal preference, as the syntax is shorter and more succinct:

df1 = [2.5, 2.5, 2, 3, 4, 3.5]
sns.set_style("whitegrid")
fig, ax = plt.subplots(figsize=(8,8))
plot1 = sns.boxplot(ax=ax, x=df1, linewidth=5)

plt.scatter(3.5, 0, marker='o', s=100)

Upvotes: 13

Scratch'N'Purr
Scratch'N'Purr

Reputation: 10399

Is this what you're looking for?

df1 = [2.5, 2.5, 2, 3, 4, 3.5]
sns.set_style("whitegrid")
fig, ax = plt.subplots(figsize=(8,8))
sns.boxplot(ax=ax, x=df1, linewidth=5)

# sns scatter, with regression fit turned off
sns.regplot(x=np.array([3.5]), y=np.array([0]), scatter=True, fit_reg=False, marker='o',
            scatter_kws={"s": 100})  # the "s" key in `scatter_kws` modifies the size of the marker

Upvotes: 4

Related Questions