网站首页 > 技术文章 正文
目录
七、 可视化
八、 其它
六.可视化
我觉得吧,其实看着excel就可以实现的功能为何那么复杂,excel确实够通用够便捷,但是处理很大数据量的话也许吃不消吧。学学python绘图也不赖,而且讲真,有的成效真的挺好看的。
(一)Seaborn
我学数据分析可视化是从学习Seaborn入门的,Seaborn是基于matplotlib的Python可视化库,刚开始便接触matplotlib难免有些吃力,参数多且难理解,但是慢慢来总会学会的。还有关键的一点是,seaborn画出来的图好好看。。
#基础导入
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib as mpl
import matplotlib.pyplot as plt
#小费数据真的挺好的,这儿用tips作为example
tips = sns.load_dataset('tips') #从网络环境导入数据tips
1.lmplot函数
lmplot(x, y, data, hue=None, col=None, row=None, palette=None, col_wrap=None, size=5, aspect=1, markers='o', sharex=True, sharey=True, hue_order=None, col_order=None, row_order=None, legend=True, legend_out=True, x_estimator=None, x_bins=None, x_ci='ci', scatter=True, fit_reg=True, ci=95, n_boot=1000, units=None, order=1, logistic=False, lowess=False, robust=False, logx=False, x_partial=None, y_partial=None, truncate=False, x_jitter=None, y_jitter=None, scatter_kws=None, line_kws=None)功能:Plot data and regression model fits across a FacetGrid.
下面就不同的例子,对lmplot的参数进行解释
例子1. 画出总账单和小费回归关系图
用到了lmplot(x, y, data,scatter_kws)
x,y,data一目了然这儿就不多解释了,scatter_kws和line_kws的官方解释如下:
{scatter,line}_kws : dictionarie
Additional keyword arguments to pass to plt.scatter and plt.plot.
scatter为点,line为线。其实就是用字典去限定点和线的各种属性,如例子所示,散点的颜色为灰石色,线条的颜色为印度红,成像效果就是这样点线颜色分离,展现效果很好。大家也可以换上自己想要的图片属性。
sns.lmplot("total_bill", "tip", tips,
scatter_kws={"marker": ".", "color": "slategray"},
line_kws={"linewidth": 1, "color": "indianred"}).savefig('picture2')
另外:颜色还可以使用RGB代码,具体对照表可以参考这个网站,可以自己搭配颜色:
http://www.114la.com/other/rgb.htm
marker也可以有多种样式,具体如下:
. Point marker,
Pixel marker
o Circle marker
v Triangle down marker
^ Triangle up marker
< Triangle left marker
> Triangle right marker
1 Tripod down marker
2 Tripod up marker
3 Tripod left marker
4 Tripod right markers
Square marker
p Pentagon marker
* Star marker
h Hexagon marker
H Rotated hexagon D Diamond marker
d Thin diamond marker
| Vertical line (vlinesymbol) marker
_ Horizontal line (hline symbol) marker
+ Plus markerx Cross (x) marker
sns.lmplot("total_bill", "tip", tips,
scatter_kws={"marker": ".","color":"#FF7F00"},
line_kws={"linewidth": 1, "color": "#BF3EFF"}).savefig('s1')
ps.我修改maker属性不成功不知为何,求解答
例子2.用餐人数(size)和小费(tip)的关系图
官方解释:
x_estimator : callable that maps vector -> scalar, optional
Apply this function to each unique value of x and plot the resulting estimate. This is useful when x is a discrete variable. If x_ci is not None, this estimate will be bootstrapped and a confidence interval will be drawn.
大概解释就是:对拥有相同x水平的y值进行映射
plt.figure()
sns.lmplot('size', 'tip', tips, x_estimator= np.mean).savefig('picture3')
{x,y}_jitter : floats, optional
Add uniform random noise of this size to either the x or y variables. The noise is added to a copy of the data after fitting the regression, and only influences the look of the scatterplot. This can be helpful when plotting variables that take discrete values.
jitter是个很有意思的参数, 特别是处理靶数据的overlapping过于严重的情况时, 通过增加一定程度的噪声(noise)实现数据的区隔化, 这样原始数据是若干 点簇 变成一系列密集邻近的点群. 另外, 有的人会经常将 rug 与 jitter 结合使用. 这依人吧.对于横轴取离散水平的时候, 用x_jitter可以让数据点发生水平的扰动.但扰动的幅度不宜过大。
sns.lmplot('size', 'tip', tips, x_jitter=.15).savefig('picture4')
seaborn还可以做出xkcd风格的图片,还挺有意思的
with plt.xkcd():
sns.color_palette('husl', 8)
sns.set_context('paper')
sns.lmplot(x='total_bill', y='tip', data=tips, ci=65).savefig('picture1')
sns.jointplot("total_bill", "tip", tips).savefig('picture9')
with plt.xkcd():
sns.lmplot('total_bill', 'tip', data=tips, hue='smoker')
plt.xlabel('hue = smoker')
plt.savefig('picture6')
sns.set_style('dark')
sns.set_context('talk')
sns.lmplot('size', 'total_bill', tips, order=2)
plt.title('# poly order = 2')
plt.savefig('picture7')
plt.figure()
sns.lmplot('size', 'total_bill', tips, order=3)
plt.title('# poly order = 3')
plt.savefig('picture8')
(二)matplotlib ********待完善
七.其它~
(一)调用R
让Python直接调用R的函数,下载安装rpy2模块即可~
具体步骤:http://www.geome.cn/posts/python-%E9%80%9A%E8%BF%87rpy2%E8%B0%83%E7%94%A8-r%E8%AF%AD%E8%A8%80/
亲测可用~ 大大大大大前提:电脑上安装了R
(二)ipython ********待完善
end.
作者:小星星.
来源:博客园.
关注我们吧,查看更多干货文章,视频。回复“数据”还有数据分析相关资料领取,每周更有免费直播课,有问题也可私信咨询小编哦!
猜你喜欢
- 2024-09-25 「机器学习」支持向量机分类 支持向量机 知乎
- 2024-09-25 数据可视化之箱线图详细介绍 箱线图绘制步骤
- 2024-09-25 简单的统计学:如何用Python计算扑克概率
- 2024-09-25 Python进行数据预处理 python如何做数据处理
- 2024-09-25 Distribution is all you need:这里有12种做ML不可不知的分布
- 2024-09-25 如何使用 Qdrant DB 创建基于向量的电影推荐系统?
- 2024-09-25 如何可视化卷积网络分类图像时关注的焦点
- 2024-09-25 感知机:教程,实现和可视示例 感知机定义
- 2024-09-25 数据处理中的“归一化”到底是什么?Talk is cheap,show me the code
- 2024-09-25 深度残差网络+自适应参数化ReLU(调参记录23)Cifar10~95.47%
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- oraclesql优化 (66)
- 类的加载机制 (75)
- feignclient (62)
- 一致性hash算法 (71)
- dockfile (66)
- 锁机制 (57)
- javaresponse (60)
- 查看hive版本 (59)
- phpworkerman (57)
- spark算子 (58)
- vue双向绑定的原理 (68)
- springbootget请求 (58)
- docker网络三种模式 (67)
- spring控制反转 (71)
- data:image/jpeg (69)
- base64 (69)
- java分页 (64)
- kibanadocker (60)
- qabstracttablemodel (62)
- java生成pdf文件 (69)
- deletelater (62)
- com.aspose.words (58)
- android.mk (62)
- qopengl (73)
- epoch_millis (61)
本文暂时没有评论,来添加一个吧(●'◡'●)