【发布时间】:2018-01-31 01:28:26
【问题描述】:
我正在尝试创建一个包含两个图的子图。第一个图本质上是散点图(我使用的是 regplot),第二个图是直方图。
我的代码如下:
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
data = {'source':['B1','B1','B1','C2','C2','C2'],
'depth':[1,4,9,1,3,10],
'value':[10,4,23,78,24,45]}
df = pd.DataFrame(data)
f, (ax1, ax2) = plt.subplots(1,2)
for source in df['source'].unique():
x = df.loc[df['source'] == source, 'value']
y = df.loc[df['source'] == source, 'depth']
sns.regplot(x,
y,
scatter = True,
fit_reg = False,
label = source,
ax = ax1)
ax1.legend()
sns.distplot(x,
bins = 'auto',
norm_hist =True,
kde = True,
rug = True,
ax = ax2,
label = source)
ax2.legend()
ax2.relim()
ax2.autoscale_view()
plt.show()
结果如下所示。
如您所见,散点图和直方图之间的颜色不同。现在,我玩弄了彩色托盘和所有东西,但没有奏效。谁能解释我如何同步颜色?
谢谢。
【问题讨论】:
标签: python pandas matplotlib colors seaborn