【Python】Seaborn 数据可视化

不同图像的绘制与保存

Scatterplot 散点图

 data = sns.load_dataset("tips")
 filepath = 'C:/Users'
 fig_name = 'scatterplot.png'

# fig_path为想要存入的文件夹或地址
 fig_path = filepath + '/' + fig_name
 fig = sns.scatterplot(x = data['total_bill'], y = data['tip'], hue = 'time', 
                data = data, palette = 'Set1', s = 100)
 scatter_fig = fig.get_figure()
 scatter_fig.savefig(fig_path, dpi = 400)

Distplot 频率分布图

x = np.random.randn(100)
x = pd.Series(x, name = "x variable")
ax = sns.distplot(x)
hist_fig = ax.get_figure()
hist_fig.savefig(fig_path, dpi = 400)

Boxplot 箱型图

fig_dims = (7.5, 4)
fig, ax = plt.subplots(figsize=fig_dims)
fig = sns.boxplot(x = data['tip'], data = data, ax = ax, orient = "h", palette = "Set2")
plt.show()
boxplot = fig.get_figure()
boxplot.savefig(fig_path, dpi=400)

Heatmap 热力图

x = np.array([[1,2,3,4], [2,3,4,6], [10,2,3,6], [8,9,7,3]])
fig_name = 'heatmap.png'
fig_path = filepath + '/' + fig_name
fig = sns.heatmap(x, annot = True)
heatmap = fig.get_figure()
heatmap.savefig(fig_path, dpi = 400)

图像尺寸、间隙、分界线等调整,可查看👇

Pairplot 多变量图

iris = sns.load_dataset("iris")
pairplot_fig = sns.pairplot(iris, kind = 'scatter', hue="species", palette="Set2", 
                                height=2.5, plot_kws=dict(s=50, alpha=0.4))
pairplot_fig.savefig(fig_path, dpi = 400)

不同颜色的选择

参考链接:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值