简体   繁体   English

seaborn 在 jupyter notebook 的单个单元格中的 python 中并排散点图

[英]seaborn scatter plots side by side in python in a single cell in jupyter notebook

I have a pandas data frame "data" with four columns age, year, nodes, status.我有一个 pandas 数据框“数据”,其中包含四列年龄、年份、节点、状态。 Status being the class/target variable which has only two values 1 - alive and 2- dead.状态是类/目标变量,它只有两个值 1 - 存活和 2 - 死亡。

sns.FacetGrid(data, hue="status", size=5).map(sns.distplot, "year").add_legend();
plt.show();
sns.FacetGrid(data, hue="status", size=5).map(sns.distplot, "age").add_legend();
plt.show();

After executing the above statements in single cell in jupyter, the output will be two plots one after another in a single cell.在jupyter中单格执行上述语句后,output会在单格中依次为两个图。

I would want to print these plots side by side in a single cell.我想在一个单元格中并排打印这些图。 Please help.请帮忙。

Try running this code!尝试运行此代码!

import matplotlib.pyplot as plt # You would have already imported this

plt.subplot(221)
sns.FacetGrid(data, hue="status", size=5).map(sns.distplot, "year").add_legend();
# plt.show();
plt.subplot(222)
sns.FacetGrid(data, hue="status", size=5).map(sns.distplot, "age").add_legend();
# plt.show(); 

Ideally, the plots should be displayed now.理想情况下,现在应该显示绘图。 If they don't, uncomment plt.show()如果他们不这样做,请取消注释plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM