Python数据可视化-seaborn库之countplot
在Python数据可视化中,seaborn较好的提供了图形的一些可视化功效。
seaborn官方文档见链接:http://seaborn.pydata.org/api.html
countplot是seaborn库中分类图的一种,作用是使用条形显示每个分箱器中的观察计数。接下来,对seaborn中的countplot方法进行详细的一个讲解,希望可以帮助到刚入门的同行。
- 导入seaborn库
import seaborn as sns
- 使用countplot
sns.countplot()
countplot方法中必须要x或者y参数,不然就报错。
官方给出的countplot方法及参数:
sns.countplot(x=None, y=None, hue=None, data=None, order=None, hue_order=None, orient=None, color=None, palette=None, saturation=0.75, dodge=True, ax=None, **kwargs)
下面讲解countplot方法中的每一个参数。以泰坦尼克号为例。
原始数据如下:
sns.set(style='darkgrid')
titanic = sns.load_dataset('titanic')
titanic.head()

x, y, hue : names of variables in ``data`` or vector data, optional. Inputs for plotting long-form data. See examples for interpretation.
- 第一种方式
x: x轴上的条形图,以x标签划分统计个数
y: y轴上的条形图,以y标签划分统计个数
hue: 在x或y标签划分的同时,再以hue标签划分统计个数
sns.countplot(x="class", data=titanic)

sns.countplot(y="class", data=titanic)

sns.countplot(x="class", hue="who", data=titanic)

- 第二种方法
x: x轴上的条形图,直接为series数据
y: y轴上的条形图,直接为series数据
sns.countplot(x=titanic['class'])

sns.countplot(y=titanic['class'])

data : DataFrame, array, or list of arrays, optional. Dataset for plotting.
If ``x`` and ``y`` are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.
data: DataFrame或array或array列表,用于绘图的数据集,x或y缺失时,data参数为数据集,同时x或y不可缺少,必须要有其中一个。
sns.countplot(x='class', data=titanic)

order, hue_order : lists of strings, optional.Order to plot the categorical levels in, otherwise the levels are inferred from the data objects.
order, hue_order分别是对x或y的字段排序,hue的字段排序。排序的方式为列表。
sns.countplot(x='class', data=titanic, order=['Third', 'Second', 'First'])

1 sns.countplot(x='class', hue='who', data=titanic, hue_order=['woman', 'man', 'child'])

orient : "v" | "h", optional
Orientation of the plot (vertical or horizontal). This is usually
inferred from the dtype of the input variables, but can be used to
specify when the "categorical" variable is a numeric or when plotting
wide-form data.
强制定向,v:竖直方向;h:水平方向,具体实例未知。
color : matplotlib color, optional
Color for all of the elements, or seed for a gradient palette.
palette : palette name, list, or dict, optional.Colors to use for the different levels of the ``hue`` variable.
Should be something that can be interpreted by :func:`color_palette`, or a dictionary mapping hue levels to matplotlib colors.
palette:使用不同的调色板
sns.countplot(x="who", data=titanic, palette="Set3")

ax : matplotlib Axes, optional
Axes object to draw the plot onto, otherwise uses the current Axes. ax用来指定坐标系。
fig, ax = plt.subplots(1, 2, figsize=(10, 5))
sns.countplot(x='class', data=titanic, ax=ax[0])
sns.countplot(y='class', data=titanic, ax=ax[1])

Python数据可视化-seaborn库之countplot的更多相关文章
- Python数据可视化-seaborn
详细介绍可以看seaborn官方API和example galler. 1 set_style( ) set( ) set_style( )是用来设置主题的,Seaborn有五个预设好的主题: d ...
- Python数据可视化的四种简易方法
摘要: 本文讲述了热图.二维密度图.蜘蛛图.树形图这四种Python数据可视化方法. 数据可视化是任何数据科学或机器学习项目的一个重要组成部分.人们常常会从探索数据分析(EDA)开始,来深入了解数据, ...
- 推荐一款Python数据可视化神器
1. 前言 在日常工作中,为了更直观的发现数据中隐藏的规律,察觉到变量之间的互动关系,人们常常借助可视化帮助我们更好的给他人解释现象,做到一图胜千文的说明效果. 在Python中,常见的数据可视化库有 ...
- Python数据可视化基础讲解
前言 本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者:爱数据学习社 首先,要知道我们用哪些库来画图? matplotlib ...
- Python数据可视化编程实战——导入数据
1.从csv文件导入数据 原理:with语句打开文件并绑定到对象f.不必担心在操作完资源后去关闭数据文件,with的上下文管理器会帮助处理.然后,csv.reader()方法返回reader对象,通过 ...
- Python数据可视化——使用Matplotlib创建散点图
Python数据可视化——使用Matplotlib创建散点图 2017-12-27 作者:淡水化合物 Matplotlib简述: Matplotlib是一个用于创建出高质量图表的桌面绘图包(主要是2D ...
- Python数据可视化编程实战pdf
Python数据可视化编程实战(高清版)PDF 百度网盘 链接:https://pan.baidu.com/s/1vAvKwCry4P4QeofW-RqZ_A 提取码:9pcd 复制这段内容后打开百度 ...
- 【数据科学】Python数据可视化概述
注:很早之前就打算专门写一篇与Python数据可视化相关的博客,对一些基本概念和常用技巧做一个小结.今天终于有时间来完成这个计划了! 0. Python中常用的可视化工具 Python在数据科学中的地 ...
- python --数据可视化(一)
python --数据可视化 一.python -- pyecharts库的使用 pyecharts--> 生成Echarts图标的类库 1.安装: pip install pyecharts ...
随机推荐
- php Header 函数使用
<?php header('HTTP/1.1 200 OK'); // ok 正常访问 header('HTTP/1.1 404 Not Found'); //通知浏览器 页面不存在 heade ...
- Mac anaconda安装 “conda command not found” 解决方法
官网下载包直接安装的时候可能会产生这种问题,这主要还是环境变量配置的问题 一般我们添加环境变量的方法是编辑.bash_profile或.bashrc,在文件里插入下面这段代码 export PATH= ...
- 【BZOJ3999】[TJOI2015]旅游(Link-Cut Tree)
[BZOJ3999][TJOI2015]旅游(Link-Cut Tree) 题面 BZOJ 洛谷 题解 一道不难的\(LCT\)题(用树链剖分不是为难自己吗,这种有方向的东西用\(LCT\)不是方便那 ...
- flutter - 01 基础介绍以及ListView
这篇主要讲flutter最基本的操作.我们从一个实例入手,先不需要知道它里面的每一行是什么意思,我会慢慢说. main.dart import 'package:flutter/material.da ...
- 微信公众、QQ群、知识星球(附比特币链接)
文章一般都会在公众号抢先预览,一个系列出差不多的时候一般博客园汇总一下(文章很长) 微信公众号:逸鹏说道(dotnetcrazy) 群友刚创建的Python中级群,有一定Python基础的可以共同探讨 ...
- python通过套接字来发送接收消息
案例如下: 1.启动一个服务端套接字服务 2.启动一个客户端套接字服务 3.客户端向服务端发送一个hello,服务端则回复一个word,并打印 参考地址:https://www.cnblogs.com ...
- MySQL实战45讲学习笔记:索引(第五讲)
一.需要回表的案例 在下面表T中,执行下面语句,需要执行几次树的搜索操作?会扫描多少行? select * from T where k between 3 and 5 1.初始化语句 mysql&g ...
- URL存在跨站漏洞http host头攻击漏洞解决方案
最近项目部署的时候客户使用的绿盟扫描出一些漏洞,老大让我处理,经过看大神的博客等方式,分享一些简单的解决方法. 一 跨网站脚本 跨网站脚本(Cross-site scripting,通常简称为XSS或 ...
- java频繁new对象的优化方案
在实际开发中,某些情况下,我们可能需要频繁去创建一些对象(new),下面介绍一种,我从书上看到的,可以提高效率的方法. 首先,对于将会频繁创建的对象,我们要让这个类实现Cloneable接口,因为这个 ...
- idea使用记录
1.在工具栏添加工具