Python3 - seaborn: lmplot(), hue, scattr_kws{}, aspect, height
本博客是在Jupyter Notebooks上测试能通过,未在IDE上测试过。
如果想了解如何创建Jupyter, 请点击这里
先提供这次使用的dataset:
import seaborn as sns
tips = sns.load_dataset('tips')
tips.head()
结果如下:
使用lmplot():
# seaborn.lmplot(): Plot data and regression model fits across a FacetGrid
sns.lmplot(x='total_bill', y='tip', data=tips)
结果如下:
使用hue来分类:
# Variables that define subsets of the data, which will be drawn on separate facets in the grid.
# hue: 用来分类
sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex')
结果如下:
# Variables that define subsets of the data, which will be drawn on separate facets in the grid.
# hue: 用来分类
sns.lmplot(x='total_bill', y='tip', data=tips, hue='smoker')
结果如下:
# Variables that define subsets of the data, which will be drawn on separate facets in the grid.
# hue: 用来分类
sns.lmplot(x='total_bill', y='tip', data=tips, hue='time')
结果如下:
使用markers:
要想使用各种各样的markers, 请点击这里
markers库的网址:https://matplotlib.org/3.3.3/api/markers_api.html
# Markers for the scatterplot. If a list, each marker in the list will be used for each level of the hue variable.
sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex', markers=['o','v'])
结果如下:
博主也设计一些测试案例来测试marker, 仅供参考:
# marker = ['s','X'] 可以用
# marker = [1,2] 也可以用这个
# marker = [3,4] 可以用
# marker = [5,6] 可以用
# marker = [5,'o'] 可以用
## marker = [+,-] 不能用 ##
# marker = ['.',','] 可以用
marker = ['+','x']
sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex', markers=marker)
结果如下:
使用scatter_kws{}:
# scatter_kws{}: Additional keyword arguments to pass to plt.scatter and plt.plot.
# s for size
sns.lmplot(x='total_bill', y='tip', data=tips, hue='sex', markers=['o','v'], scatter_kws={'s':100})
结果如下:
如果要想改变scatter_kws字典里的内容,可以尝试这样:(仅供参考)
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
import seaborn as sns# Create data frame. The last column is the needed color
df = pd.DataFrame(np.random.random((100,2)), columns=["x","y"])# Add a column: the color depends of x and y values, but you can use whatever function.
value=(df['x']>0.2) & (df['y']>0.4)
df['color']= np.where( value==True , "#9b59b6", "#3498db")# plot
sns.regplot(data=df, x="x", y="y", fit_reg=False, scatter_kws={'facecolors':df['color']})
结果如下:
使用col:
# col: 根据所指定属性在列上分类
sns.lmplot(x='total_bill', y='tip', data=tips, col='sex')
结果如下:
使用row:
# row: 根据所指定属性在行上分类
sns.lmplot(x='total_bill', y='tip', data=tips, col='sex', row='time')
结果如下:
使用col和row:
sns.lmplot(x='total_bill', y='tip', data=tips, col='day', row='time', hue='sex')
结果如下:
使用aspect 和 height来控制图形的清晰度:
这个案例的aspect * height = 4.8
# aspect: Aspect ratio of each facet, so that aspect * height gives the width of each facet in inches
# height: Height (in inches) of each facet.
# aspect * height 所得到的结果越大,图形越模糊
sns.lmplot(x='total_bill', y='tip', data=tips, col='day', hue='sex', aspect=0.6, height=8)
结果如下:
这个案例的aspect * height = 3.2:
sns.lmplot(x='total_bill', y='tip', data=tips, col='day', hue='sex', aspect=0.8, height=4)
结果如下:
这个案例使用aspect * height = 7:
sns.lmplot(x='total_bill', y='tip', data=tips, col='day', hue='sex', aspect=0.7, height=10)
结果如下:
如果觉得不错,就点赞或者关注或者留言~~
谢谢~ ~
Python3 - seaborn: lmplot(), hue, scattr_kws{}, aspect, height相关推荐
- seaborn系列 (17) | 回归模型图lmplot()
目录 回归模型图 函数原型 参数解读 案例教程 案例地址 回归模型图 回归模型图可以对数据进行回归显示. 函数原型 seaborn.lmplot(x, y, data, hue=None,col=No ...
- 用Python的Seaborn库绘制17个超好看图表
Seaborn简介 定义 Seaborn是一个基于matplotlib且数据结构与pandas统一的统计图制作库.Seaborn框架旨在以数据可视化为中心来挖掘与理解数据. 优点 代码较少 图形美观 ...
- 【Python】Python Seaborn搞定线型回归图曲线
本文详细介绍Seaborn可视化线型回归(linear regression)曲线 目录 1.绘图数据准备 2.seaborn.regplotregplot默认参数线型回归图分别设置点和拟合线属性置信 ...
- Seaborn 各种图形绘制
Seaborn是基于matplotlib的图形可视化python包.它提供了一种高度交互式界面,便于用户能够做出各种有吸引力的统计图表. Seaborn是在matplotlib的基础上进行了更高级的A ...
- Python设置画布大小_我用Python的Seaborn库绘制17个超好看图表
点击上方" Python爬虫与数据挖掘 ",进行关注 回复"书籍"即可获赠Python从入门到进阶共10本电子书 今 日 鸡 汤 风朝露夜阴晴里,万户千门开闭时 ...
- 我用Python的可视化工具Seaborn制作17个超好看常用图表
一.Seaborn简介 1.定义 Seaborn是一个基于matplotlib且数据结构与pandas统一的统计图制作库. Seaborn框架旨在以数据可视化为中心来挖掘与理解数据. 2.优点 代码较 ...
- Seaborn常见绘图总结
以前粗略的学习过Matplotlib绘图.Pandas绘图(这里是pandas的常见绘图总结),但是都未深入的去学习过,一遇到问题就翻文档,效率低下.听"他们"说matplotli ...
- 详解Seaborn,看这一篇就够了
转载:Seaborn常见绘图总结 Seaborn是一个比Matplotlib集成度更高的绘图库,在科研和数据分析中我们常常看到一些画的非常高大上的图,这往往就是Seaborn绘制的图形.因此我们就使用 ...
- seaborn.FacetGrid
官方文档链接:https://www.cntofu.com/book/172/docs/32.md 一.函数 class seaborn.FacetGrid(data, row=None, col=N ...
最新文章
- 英特尔大地震!解雇首席工程官,7纳米延期,或面临集体诉讼……
- AlphaFold2被超越!中国团队刷新全球蛋白质结构预测纪录,大牛彭健创业项目一鸣惊人...
- 深度学习利器:TensorFlow在智能终端中的应用——智能边缘计算,云端生成模型给移动端下载,然后用该模型进行预测...
- 参与 Apache 顶级开源项目的 N 种方式,Apache Dubbo Samples SIG 成立!
- php mysql-mysqli
- 【剪枝算法】通过网络瘦身学习高效的卷积网络Learning Efficient Convolutional Networks through Network Slimming论文翻译
- 启动Eureka客户端服务时报错:java.net.ConnectException: Connection refused:connect
- Python进行websocket接口测试
- 利用Multisim快速分析一个RC电路
- Xcode 7.3 解决自定义类无法自动联想
- springboot-增加自定义资源映射
- qt 分辨率问题 安卓_Qt for Android dp转换
- Linux 内核软中断(softirq)执行分析
- pgadmin4下载
- B.FRIENDit壁虎忍者品牌故事
- ping丢包故障处理
- mybatis官方文档中文版
- 控制翻页c语言,阅读器多种翻页的设计与实现
- 苹果开发者 安卓开发者 谷歌广告Admob 跨境电商 海外收款和收取美金方法
- [ros robot] --- 机器人系统仿真
热门文章
- zookeeper初步
- java d打字游戏_练习--java实现的打字游戏
- 基于SpringBoot+Vue前后端分离的在线教育平台项目
- 旷厂练习生 Vol.16 | 两次进入研究院里的“研究院”实习是种什么体验?
- 如何使用腾讯云轻量服务器以及WooCommerce 应用镜像搭建跨境电商独立站!
- Google Paly 上传支持64 位设备APP
- 怎么样才能进入BAT公司的研发部门
- 购买学校计算机房加密狗的请示,2015关于扩建机房的请示.doc
- 线性规划 - 数学建模
- 审阅模式中word保存不了