简体   繁体   中英

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:

在此处输入图像描述

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 散点图

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM