【发布时间】:2021-08-22 12:28:52
【问题描述】:
【问题讨论】:
-
这里有与您和answers相同的问题。
-
使用
ax2 = ax1.twinx(),然后在ax2上绘制第二个数据集
【问题讨论】:
ax2 = ax1.twinx(),然后在ax2上绘制第二个数据集
这是一个使用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')
输出:
【讨论】:
试试这个:(设置color使用hue,设置shape使用style)
import seaborn as sns
import pandas as pd
import numpy as np
import random
sns.set_theme(style="white")
data = pd.DataFrame({'x': np.random.random(size=300),
'y': np.random.random(size=300),
'color' : random.choices([0,1,2], k=300),
'weight' : random.choices([10,20], k=300)
})
sns.relplot(x="x", y="y", hue="color", size="weight", style = "color",
sizes=(40, 400), alpha=.5, palette="muted", data=data)
输出:
【讨论】: