Data Visualization

Matplotlib and seaborn

Tell a Story

  • Engage audience with hierarchical summarized insights

  • Process 1. organize initial story and insights 2. who is your audience and what are they interested in 3. the high-level insights 4. correlation between the insights 5. how will the insights change the audience's mind or help them make decision

可视化的基本原则

  • story focus, supported by visualization

  • data dimension in a chart: 2D

  • attentive attributes: color, highlight

  • less is more: remove distraction

Tableau

Import Package

Basic of Matplotlib

Stateful vs stateless (OOP) approach

  • Stateful approach

线图点图:

优点:简单快捷 缺点:缺乏灵活性

  • Stateless (OOP) approach

比如同样是画三条线,对比这两种approach

更灵活的做法stateless里,还可以

调节coordinate objects

  • adjust background color

  • adjust gridline

  • set x-axis label and y-axis label

  • adjust x-axis and y-axis ticks

用for loop来subplot

拿到一个新的数据 如何visualize

双y轴

Seaborn

  • 用seaborn作图

  • 用matplotlib微调

  • 加theme

语法上和R的ggplot很像

对比stateful vs stateless

unstack

sns里面自己内置了很多groupby似的操作 帮着slice了数据 方便哭了

factor plot

id

diet

pulse

time

kind

0

1

low fat

85

1 min

rest

1

1

low fat

85

15 min

rest

2

1

low fat

88

30 min

rest

3

2

low fat

90

1 min

rest

4

2

low fat

92

15 min

rest

FacetGrid

FacetGrid 是一个绘制多个图表(以网格形式显示)的接口。

步骤: 1、实例化对象 2、map,映射到具体的 seaborn 图表类型 3、添加图例

row='Sex', col='Pclass' 是什么效果。

Regression Plot

更多例子

Last updated