我正在嘗試使用seaborn
-package(因爲它似乎是跨類別使用顏色映射的一種簡潔方式)將散點圖和線條圖相結合。結合彩色散點圖和單獨的線條圖
目前我有兩個數據集存儲爲熊貓數據框:linear_data
爲線性情況下,scatter_data
爲散射數據。我可以創建兩個單獨的地塊爲這樣:
import seaborn as sns
import numpy as np
import matplotlib.pyplot as plt
# creating a nice color palette with 10 different colors
color_palette=sns.diverging_palette(10, 130, sep=100, n=10)
N=300
scatter_data = pd.DataFrame({'x' : np.random.random(N)*10, 'y' :
np.random.random(N)*100, 'score' : np.random.randint(1,10,N)})
# create linear plot for linear_data
lin_dict = {0.1: 51.98384470434041,
0.25: 69.9192341826548,
0.5: 83.48683256238559,
1.0: 97.05443094211638,
2.0: 110.62202932184718,
3.0: 118.5585655988348,
4.0: 124.18962770157796,
5.0: 128.55741880016157,
6.0: 132.1261639785656,
7.0: 135.1434950339544,
8.0: 137.75722608130874,
9.0: 140.06270025555324,
10.0: 142.12501717989235}
linear_data = pd.DataFrame.from_dict(lin_dict, orient='index').sort_index();
linear_data.index.name='x'; linear_data.columns = ['y']
ax = sns.pointplot(x=linear_data.index, y=linear_data['y'], data=linear_data)
# create scatter plot for scatter_data, having color scheme
# as in color_palette mapped onto the column 'score' (ranging from 1-10)
fg = sns.FacetGrid(data=scatter_data, hue='score', palette=color_palette, size=5, aspect=1.5)
fg.map(pyplot.scatter, 'x', 'y').add_legend()
因此,而不是單獨爲這兩個,我顯然希望有他們在同樣的情節!我找不到FacetGrid
採取任何ax
-variable,所以沒有對如何將二者連接真的相信......
NEW:正如評論所說,我想點linear_data
是在散點圖較低,但是的線條與這些點互相連接(顯然顏色與散射中使用的顏色不同,例如黑色)
對此的解決方案的任何線索?
請提供可重複的數據和所有'import'線作爲我看到了'pyplot.'電話。 – Parfait
你想要一個像[this one]這樣的共享x軸的子區域(https://matplotlib.org/mpl_examples/pylab_examples/subplots_demo_01.png)嗎? –
我剛剛添加了重現性數據... – gussilago