Python Relplot with distinct lines

Viewed 216

I want to create a plot with Seaborn by using relplot for the following plot:

enter image description here

My code so far is:

f = sns.relplot(
    data = data,
    x="year",
    y="gdpPercap",
    hue="continent",
    col="continent",
    col_wrap=3,
    height=2,
    aspect=1.5,
    alpha=0.5,
    kind="line",
)

for ax in f.axes.flatten():
    ax.semilogy()

However, my plot looks like this:

enter image description here

How do I change the plot so that each line represent each data?

1 Answers

Use units to draw a separate line without any additional semantic mapping:

g = sns.relplot(
    data=gapminder,
    kind="line",
    x="year",
    y="gdpPercap",
    hue="continent",
    col="continent",
    units="country",
    estimator=None,
    col_wrap=3,
    height=3,
    alpha=0.5,
)
g.set(yscale="log")

enter image description here

PS note that it is not necessary to loop over the axes to get a log-scaled y axis...

Related