CWWW
CWWW

Reputation: 3

seaborn plot with two y axis

I have some data and need to generate a plot like this image, I just wonder how to do this using python seaborn scatter plot? Thanks, heaps! example:

enter image description here

Upvotes: 0

Views: 4512

Answers (1)

mozway
mozway

Reputation: 262359

Here is a minimal example using seaborn.scatterplot:

import pandas as pd
import seaborn as sns
import numpy as np
np.random.seed(0)
df1 = pd.DataFrame({'x': np.random.random(size=10),
                    'y1': np.random.random(size=10),
                   })
df2 = pd.DataFrame({'x': np.random.random(size=10),
                    'y2': np.random.random(size=10)*100,
                   })
ax1 = plt.subplot()
ax2 = ax1.twinx()
sns.scatterplot(data=df1, x='x', y='y1', ax=ax1)
sns.scatterplot(data=df2, x='x', y='y2', color='r', ax=ax2)
ax2.tick_params(axis='y', colors='red')

output:

twinx seaborn scatterplot

Upvotes: 4

Related Questions