2020-12-11
数据分析
00

title: 学习 seaborn [04]: 修改样式、移动座标轴 slug: beautify-seaborn date: 2020-12-11 16:23:05 tags:

  • seaborn
  • python category: 数据分析 link: description: type: text

控制图像的美学样式

相比与matplotlib详细的样式设置,seaborn提供了成套的样式主题可供直接使用,同时提供高级设置接口供用户自定义主题。

以装修房子比喻,用matplotlib就像全部考自己装修,窗台、地砖、墙壁等细节都要自己考虑,费时费力但高度可定制化。而用seaborn相当于从装修公司已设计好的装修方案中挑选一个,然后还能在此基础进行部分的修改定制。

显然seaborn在效率和美观之间能达到平衡。

seaborn设置样式主要用到这几个函数:

  • axes_style()set_style():设置图像样式,前者用于返回样式设置的参数字典;
  • plotting_context()set_context():设置元素样式,前者用于返回样式设置的参数字典;
  • despine():移除座标轴或修改座标轴位置。
2020-12-09
数据分析
00

title: 学习 seaborn [03]: 线性回归图 slug: lmplot date: 2020-12-9 tags:

  • seaborn
  • python category: 数据分析 link: description: type: text

线性关系可视化

此线性可视化并非统计关系中的折线图,而是excel做图中的趋势线概念,对x、y关系进行线性拟合得到关系式,对关系式的绘图。

seaborn的线性可视化不直接提供拟合关系式的各具体参数,只绘制出趋势线和置信区间,从而引导和帮助进行数据关系探索。

主要用到两个函数:

  • lmplot():FacetGrid级函数,可绘制多子图;将data作为必须参数,x和y变量必须被指定为字符串。
  • regplot():轴级函数。x和y可以是简单的 numpy 数组,pandas Series对象,或者作为对传递给data的 pandas DataFrame对象。
2020-12-03
数据分析
00

可视化分类数据

可视化分类数据的统一FacetGrid图级接口为catplot()函数,通过kind参数,可以选择轴级函数有:

  • 分类散点图:
    • stripplot() (with kind="strip"; the default)
    • swarmplot() (with kind="swarm")
  • 分类分布图:
    • boxplot() (with kind="box")
    • violinplot() (with kind="violin")
    • boxenplot() (with kind="boxen")
  • 分类估计图:
    • pointplot() (with kind="point")
    • barplot() (with kind="bar")
    • countplot() (with kind="count")
2020-11-30
数据分析
00

title: 学习 seaborn [01]: 散点图 & 线型图 slug: seaborn-scatter-line date: 2020-11-30 tags:

  • seaborn
  • python category: 数据分析 link: description: type: text

可视化统计关系

表示统计关系的图分为散点图和线型图两类。统一的FacetGrid图级接口函数为relplot()。

散点图

python
import seaborn as sns import pandas as pd %matplotlib inline # seaborn预设主题:darkgrid(默认),whitegrid,dark,white 以及 ticks sns.set() # 导入数据集。由于sns.load_dataset连接不上服务器,使用pandas导入本地下载的数据集 tips = pd.read_csv('seaborn-data-master/tips.csv') display(tips)
2020-11-22
方法工具
00

最近发现一豆瓣博主写的基金类日记很有启发,但由于博主至少一个礼拜才更新一篇,看新文章时旧文章都记不清了,于是想把日记保存成电子书再从头看一遍。

想起 Calibre 有通过 RSS 将抓取的文章生成电子书的功能,刚好豆瓣日记也提供 RSS 订阅源,于是就开始尝试一下。

本方法也适用于豆瓣以外其他内容平台,前提是能找到相应的 RSS 订阅源。