在一个图中使用Seaborn绘制多个不同的图表。
在一个图中使用Seaborn绘制多个不同的图表。
我正在尝试使用seaborn重新创建《统计学习导论》一书中的以下图表。我特别想使用seaborn的lmplot创建前两个图表,使用boxplot创建第二个图表。主要问题是lmplot根据这个回答创建了一个facetgrid,这迫使我在boxplot中hackily添加另一个matplotlib axes。我想知道是否有更简单的方法来实现这一点。在下面的代码中,我必须进行相当多的手动操作才能得到所需的图表。
以下是样本数据的DataFrame:
df_melt = {'education': {0: '1. < HS Grad',
1: '4. College Grad',
2: '3. Some College',
3: '4. College Grad',
4: '2. HS Grad'},
'value': {0: 18, 1: 24, 2: 45, 3: 43, 4: 50},
'variable': {0: 'age', 1: 'age', 2: 'age', 3: 'age', 4: 'age'},
'wage': {0: 75.043154017351497,
1: 70.476019646944508,
2: 130.982177377461,
3: 154.68529299562999,
4: 75.043154017351497}}
df_wage={'education': {0: '1. < HS Grad',
1: '4. College Grad',
2: '3. Some College',
3: '4. College Grad',
4: '2. HS Grad'},
'wage': {0: 75.043154017351497,
1: 70.476019646944508,
2: 130.982177377461,
3: 154.68529299562999,
4: 75.043154017351497}}
我将使用seaborn的lmplot创建前两个图表,使用boxplot创建第二个图表。主要问题是lmplot根据此答案创建了一个facetgrid,这迫使我hackily添加另一个matplotlib axes来创建boxplot。是否有更简单的方法来实现这一点?在下面的代码中,我需要进行一些手动操作才能得到所需的图表。