我正在尝试创建一个包含两个图表的子图。第一个图表基本上是一个散点图(我正在使用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()
结果如下所示。
正如您所看到的,散点图和直方图之间的颜色是不同的。我已经尝试了调整颜色板等方法,但都没有成功。有谁能够提供一些帮助,告诉我如何同步这些颜色呢?