python可视化进阶---seaborn1.9 时间线图表、热图 tsplot() / heatmap()

简介: 时间线图表、热图tsplot() / heatmap()

时间线图表、热图

tsplot() / heatmap()

1.时间线图表 - tsplot()

示例1:

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#设置风格、尺度
sns.set_style('darkgrid')
sns.set_context('paper')
#不发出警告
import warnings
warnings.filterwarnings('ignore')
x = np.linspace(0, 15, 31)
data = np.sin(x) + np.random.rand(10,31) + np.random.randn(10,1)
print(data.shape)
print(pd.DataFrame(data).head())
sns.tsplot(data = data,
           err_style='ci_band', #误差数据风格,可选:ci_band, ci_bars, boot_traces,
           #boot_kde, unit_traces, unit_points
           interpolate = True,  #设置连线
           ci = [40, 70, 90],   #设置误差区间
           color = 'g'          #设置颜色
           )

20180911154730800.png

示例2:

sns.tsplot(data = data, err_style = 'boot_traces',
           n_boot = 300   #迭代次数
           )

20180911154826126.png

示例3:

#参数设置
#导入数据
gammas = sns.load_dataset('gammas')
print(gammas.head())
print('数据量为:%i条'%len(gammas))
print('timepoint为0.0时的数据量为:%i条'%len(gammas[gammas['timepoint'] == 0]))
#查看唯一具体信息
print('timepoint共有%i个唯一值'%len(gammas['timepoint'].value_counts()))
sns.tsplot(time = 'timepoint',    #时间数据, x轴
           value = 'BOLD signal', #y轴value
           unit = 'subject',      #拆分,默认参数
           condition = 'ROI',     #分类
           data = gammas
           )

20180911154905574.png

2、热图 - heatmap()

示例1:

df = pd.DataFrame(np.random.rand(10,12))
sns.heatmap(df, #加载数据
            vmin = 0, vmax = 1 #设置图例最大最小值
            )

20180911154949376.png

示例2:设置参数

#设置参数
#加载数据
flights = sns.load_dataset('flights')
flights = flights.pivot('month','year','passengers')
print(flights.head())
sns.heatmap(flights,
            annot = True,   #是否显示数值
            fmt = 'd',      #格式化字符串
            linewidth = 0, #格子边线宽度
            center = 100,   #调色盘的色彩中心值,若没有指定,则以cmap为主
            cmap = 'Reds',  #设置调色盘
            cbar = True,     #是否显示图例色带
            #bar_kws = ['orientaion':'horizaintal'], #是否横向显示图例色带
            #square = True   #是否正方形显示图表
            )

2018091115510390.png

示例3:绘制半边热图

#设置风格
sns.set(style = 'white')
#创建数据
rs = np.random.RandomState(33)
d = pd.DataFrame(rs.normal(size = (100, 26)))
corr = d.corr()  #求解相关性矩阵表格
#设置一个‘上三角形’蒙版
mask = np.zeros_like(corr, dtype = np.bool)
mask[np.triu_indices_from(mask)] = True
#设置调色盘
cmap = sns.diverging_palette(220, 10, as_cmap = True)
#生成半边热图
sns.heatmap(corr, mask = mask, cmap = cmap, vmax = .3, center = 0,
            square = True, linewidths = 0.2)

20180911155210296.png

相关文章
|
2月前
|
数据可视化 搜索推荐 大数据
基于python大数据的北京旅游可视化及分析系统
本文深入探讨智慧旅游系统的背景、意义及研究现状,分析其在旅游业中的作用与发展潜力,介绍平台架构、技术创新、数据挖掘与服务优化等核心内容,并展示系统实现界面。
|
2月前
|
数据可视化 数据挖掘 大数据
基于python大数据的水文数据分析可视化系统
本研究针对水文数据分析中的整合难、分析单一和可视化不足等问题,提出构建基于Python的水文数据分析可视化系统。通过整合多源数据,结合大数据、云计算与人工智能技术,实现水文数据的高效处理、深度挖掘与直观展示,为水资源管理、防洪减灾和生态保护提供科学决策支持,具有重要的应用价值和社会意义。
|
2月前
|
机器学习/深度学习 搜索推荐 数据可视化
基于python大数据的音乐可视化与推荐系统
本研究基于Python实现音乐数据采集、清洗、分析与可视化,并结合协同过滤算法构建个性化推荐系统。通过Echarts展示音乐热度及用户偏好,提升用户体验,助力音乐产业智能化发展。
|
2月前
|
搜索推荐 算法 大数据
基于python大数据的旅游景点可视化与推荐系统
本系统基于大数据与网络技术,构建个性化旅游推荐平台。通过收集用户偏好及行为数据,结合机器学习算法,提供精准的旅游目的地、住宿及交通推荐,旨在优化旅游信息传递,提升用户决策效率与旅行体验。
|
3月前
|
数据采集 数据可视化 API
驱动业务决策:基于Python的App用户行为分析与可视化方案
驱动业务决策:基于Python的App用户行为分析与可视化方案
|
数据采集 数据可视化 IDE
用Python获得电影数据并可视化分析
用Python获得电影数据并可视化分析
233 0
|
数据采集 JSON 数据可视化
【Python实战】Python对中国500强排行榜数据进行可视化分析
【Python实战】Python对中国500强排行榜数据进行可视化分析
|
机器学习/深度学习 存储 数据可视化
数据分享|Python在Scikit-Learn可视化随机森林中的决策树分析房价数据
数据分享|Python在Scikit-Learn可视化随机森林中的决策树分析房价数据
176 12

推荐镜像

更多