seaborn箱线图

Hello, folks! In this article, we will be taking the Seaborn tutorial ahead and understanding the Seaborn Line Plot. We recently covered Seaborn HeatMaps so feel free to have a look if you’re interested in learning more about heatmaps.

大家好! 在本文中,我们将继续进行Seaborn教程,并了解Seaborn Line Plot 。 我们最近介绍了Seaborn HeatMaps,因此如果您有兴趣了解有关热图的更多信息,请随时查看。



什么是线图? (What is a Line Plot?)

Seaborn as a library is used in Data visualizations from the models built over the dataset to predict the outcome and analyse the variations in the data.

Seaborn是一个库,可用于在数据集中建立的模型的数据可视化中 ,以预测结果并分析数据的变化。

Seaborn Line Plots depict the relationship between continuous as well as categorical values in a continuous data point format.

Seaborn线图以连续数据点格式描述连续值和分类值之间的关系。

Throughout this article, we will be making the use of the below dataset to manipulate the data and to form the Line Plot. Please go through the below snapshot of the dataset before moving ahead.

在整个本文中,我们将使用以下数据集来操纵数据并形成线图。 在继续操作之前,请仔细阅读下面的数据集快照。

In the below dataset, the data variables — ‘cyl‘, ‘vs‘, ‘am‘, ‘gear‘ and ‘carb‘ are categorical variables because all the data values fall under a certain category or range of values.

在下面的数据集中,数据变量“ cyl ”,“ vs ”,“ am ”,“ gear ”和“ carb ”是分类变量,因为所有数据值都属于某个类别或值范围。

While the remaining data column falls under the integer/continuous variables because they carry discrete integer values with them.

而剩余的数据列属于整数/ 连续变量,因为它们带有离散整数值。

Input Dataset:

输入数据集:

MTCARS DatasetMTCARS数据集


绘制您的第一个Seaborn线图 (Plotting Your First Seaborn Line Plot)

In order to start with Line Plots, we need to install and import the Seaborn Library into the Python environment by using the below command:

为了从线图开始,我们需要使用以下命令将Seaborn库安装并导入到Python环境中:

Syntax:

句法:


pip install seaborn

Once you are done with the installation, import the library to the current working environment and use the functions

完成安装后,将库导入到当前工作环境并使用功能

Syntax:

句法:


import seaborn

For the entire series of Seaborn, we will be using Matplotlib library to plot the data and show it in a proper visualized manner.

对于整个Seaborn系列,我们将使用Matplotlib库绘制数据并以适当的可视化方式显示。



使用Seaborn创建单线图 (Creating Single LinePlot with Seaborn)

We can supply discrete values or use data sets to create a Seaborn line plot.

我们可以提供离散值或使用数据集来创建Seaborn线图。

Syntax:

句法:


seaborn.lineplot(x, y, data)
  • x: Data variable for the x-axisx :x轴的数据变量
  • y: The data variable for the y-axisy :y轴的数据变量
  • data: The object pointing to the entire data set or data valuesdata :指向整个数据集或数据值的对象

Example 1: Using random data to create a Seaborn Line Plot

示例1:使用随机数据创建Seaborn线图


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltYear = [2012, 2014, 2016, 2020, 2021, 2022, 2018]
Profit = [80, 75.8, 74, 65, 99.5, 19, 33.6]data_plot = pd.DataFrame({"Year":Year, "Profit":Profit})sns.lineplot(x = "Year", y = "Profit", data=data_plot)
plt.show()

In the below line-plot, we can witness the linear relationship between the two data variables — ‘Year’ and ‘Profit’.

在下面的线图中,我们可以看到两个数据变量“年”和“利润”之间的线性关系。

Output:

输出:

LinePlot Example 1LinePlot示例1

Example 2: Using a Dataset to create a Line Plot and depict the relationship between the data columns.

示例2:使用数据集创建线图并描述数据列之间的关系。


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,:5]
sns.lineplot(x = "drat", y = "mpg",data=info)
sns.set(style='dark',)
plt.show()

Input Dataset:

输入数据集:

Input Dataset Seaborn LinePlot输入数据集Seaborn LinePlot

Output:

输出:

LinePlot Example 2LinePlot示例2


多个Seaborn线图 (Multiple Seaborn Line Plots )

We can create multiple lines to visualize the data within the same space or plots. We can use the same or multiple data columns/data variables and depict the relationship between them altogether.

我们可以创建多条线以可视化同一空间或图中的数据。 我们可以使用相同或多个数据列/数据变量,并完全描述它们之间的关系。

1.使用hue参数为多个数据点创建颜色 (1. Using the hue Parameter To Create Color Hue for Multiple Data Points)

The parameter hue can be used to group the different variables of the dataset and would help depict the relationship between the x and the y-axis data columns with the column passed as a value to the parameter.

参数hue可用于对数据集的不同变量进行分组,并有助于描述x和y轴数据列之间的关系,并将该列作为值传递给参数。

Syntax:

句法:


seaborn.lineplot(x,y,data,hue)

Example:

例:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,:5]
sns.lineplot(x = "drat", y = "mpg", data=info, hue="cyl")
plt.show()

As seen in the below plot, it represents three lines with a different color scheme to depict the relationship between the ‘drat‘, ‘mpg‘ and ‘cyl‘ respectively.

如下图所示,它代表了三行具有不同配色方案的线,分别描绘了' drat ',' mpg '和' cyl '之间的关系。

Output:

输出:

Multiple Seaborn LinePlot多个Seaborn线图


2.使用style参数绘制不同类型的线 (2. Using the style Parameter to Plot Different Types of Lines)

We can set the style parameter to a value that we’d like to display along with the x and the y-axis and also specify different line structures: dash, dots(markers), etc.

我们可以将样式参数设置为一个要与x和y轴一起显示的值,还可以指定不同的线结构:破折号,点(标记)等。

Syntax:

句法:


seaborn.lineplot(x, y, data, style)

Example 2:

范例2:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,:5]
sns.lineplot(x = "drat", y = "mpg", data=info, hue="cyl", style="cyl")
plt.show()

As seen clearly, the plot represents the ‘cyl’ values in relation with ‘mpg’ and ‘drat’ with different line structures i.e. plain line, dashes and markes.

可以清楚地看到,该图表示与“ mpg”和“ drat”相关的“ cyl”值,并具有不同的线结构,即普通线,虚线和标记。

Output:

输出:

Line Plot With style Parameter带有样式参数的线图


3.使用size参数在Seaborn中绘制多个线图 (3. Using size parameter to plot multiple line plots in Seaborn)

We can even use the size parameter of seaborn.lineplot() function to represent the multi data variable relationships with a varying size of line to be plotted. So it acts as a grouping variable with different size/width according to the magnitude of the data.

我们甚至可以使用seaborn.lineplot() functionsize参数来表示具有可变大小的待绘制线的多数据变量关系。 因此,它根据数据的大小充当大小/宽度不同的分组变量。

Syntax:

句法:


seaborn.lineplot(x, y, data, size)

Example 3:

范例3:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,]
sns.lineplot(x = "drat", y = "mpg", data=info, hue="gear",style="gear",size="gear")
plt.show()

Input Dataset:

输入数据集:

Dataset For Multiple Line Plot多线图数据集

Output:

输出:

Line Plot With size Parameter带有大小参数的线图


与线图一起使用不同的调色板 (Using different color palette along with Line Plot)

Seaborn colormap and palette define the color range for the visualization models. The parameter palette along with hue can be used for determining the color encoding scheme in terms of the data variable.

Seaborn颜色图和调色板定义了可视化模型的颜色范围。 参数palettehue可用于根据数据变量确定颜色编码方案。

For more color palettes, you can reference the link here: Color Palette

有关更多调色板,您可以在此处引用链接: 调色板

Syntax:

句法:


seaborn.lineplot(x,y,data,hue,palette)

Example:

例:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,]
sns.lineplot(x = "drat", y = "mpg", data=info, hue="gear", palette = "Set1")
plt.show()

Output:

输出:

Line Plot Palette
线图调色板


误差线添加到线图 (Addition of Error Bars to Line Plot)

Line Plots can be used to define the confidence levels/intervals in the plots to depict the error rates through the use of err_style parameter.

线图可用于定义图中的置信度水平/区间,以通过使用err_style参数来描述错误率。

Syntax:

句法:


seaborn.lineplot(x,y,data,err_style="bars")

Example:

例:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,]
sns.lineplot(x = "cyl", y = "mpg",data=info, err_style="bars")
plt.show()

Output:

输出:

Line Plot With err_style Parameter带有err_style参数的线图


使用seaborn.set()函数设置不同的样式 (Setting different style using seaborn.set() function)

Python seaborn.set() function can be used to display the plot in a different background style.

Python seaborn.set() function可用于以不同背景样式显示图。

Syntax:

句法:


seaborn.set(style)

Example:

例:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as pltdata = pd.read_csv("C:/mtcars.csv")
info = data.iloc[1:20,]
sns.lineplot(x = "cyl", y = "mpg",data=info,hue="gear")
sns.set(style='dark',)
plt.show()

Output:

输出:

Line Plot With set() function带有set()函数的线图


结论 (Conclusion)

Thus, in this article, we have understood the Line Plots and the variations associated with it.

因此,在本文中,我们已经了解了线图及其相关的变化。

I strongly recommend the readers to go through Python Matplotlib tutorial to understand the Line Plots in a better manner.

我强烈建议读者阅读Python Matplotlib教程 ,以更好的方式了解线图。



参考资料 (References)

  • Seaborn Line Plot — Official DocumentationSeaborn线图—官方文档

翻译自: https://www.journaldev.com/39342/seaborn-line-plot

seaborn箱线图

seaborn箱线图_Seaborn线图的数据可视化相关推荐

  1. python绘制漂亮的线_使用PyQtGraph进行Python数据可视化:绘制精美线图(以上证指数走势为例)...

    在上两篇文章中,我们介绍了: 本篇文章将介绍使用PyQtGraph绘制一个精美折线图, 在了解了基本的PyQtGraph模块绘制图形功能之后,我们通过几个常用常见的数据可视化图形来演示使用PyQtGr ...

  2. graphpad做折线图坐标轴数字_pandas做数据可视化具体操作,快来看看吧

    常见的数据可视化库有: matplotlib 是最常见的2维库,可以算作可视化的必备技能库,由于matplotlib是比较底层的库,api很多,代码学起来不太容易. seaborn 是建构于matpl ...

  3. python折线图怎么添加数值_Python数据可视化:如何创建曲线图

    一图胜千言,使用Python的matplotlib库,可以快速创建高质量的图形. 用matplotlib生成基本图形非常简单,只需要几行代码,但要创建复杂的图表,需要调用更多的命令和反复试验,这要求用 ...

  4. 比较两组数据的差异用什么图更直观_科研数据可视化:巧妙运用各种形式的图表...

    导读: 图片和表格不仅是讲述科研故事的有力工具,也是科学出版物的重要组成部分.科研论文数量种类庞杂,在这个快节奏的时代,为了更高效地获取论文的重要信息,读者通常会跳过稿件的正文,而主要查看文中图表所传 ...

  5. 图大杀猫:数据可视化的真善美

    数据,听起来是与普通生活几乎毫无关联的词汇,如果不是从事运营.UI.产品.技术等相关领域,或者爱好炒炒股.买买彩票,数据几乎与大多数人不会扯上什么关系. 我们先来看看数据与数据可视化的大体释义-- 数 ...

  6. python三维图能画地图_Python数据可视化:3D动态图,让你的足迹实现在地图上

    本文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 以下文章来源于python数据分析之禅 ,作者小dull鸟 今天给大家带来一篇3 ...

  7. 【用pandas_alive几行代码绘制竞赛动图】全网首发pandas_alive数据可视化中文学习笔记合集,学不会来打我(配置好的venv虚拟环境+拿来即用测试代码+测试数据集+参数api解析)

    目录 专栏说明 一.效果图展示 1.1 水平条形图 1.2 竖直条形图 2. 折线图 3. 散点图 4.饼状图 5. 气泡图 6.1 地理空间点图 6.2 多边形地理空间图 7.多个图表 8.城市人口 ...

  8. 多元统计分析——各类图的具体应用(数据可视化)

    1.轮廓图 1.1 基本介绍 在二维直角坐标系中,将 n 次观测值可画出 n 条折线构成轮廓图,其中横坐标表示各个变量,纵坐标表示与变量取值成正比的数值. 作图步骤 (1) 作直角坐标系,横坐标取 p ...

  9. 网页开发 与数据联动的图_零基础学习数据可视化pyecharts人物关系图开发

    Pyecharts人物关系图开发 1. Pyecharts版本说明 Pyecharts的版本最新版本为1.7.0版本,此版本跟0.5版本的使用方法不一样了.很多参数方法配置不一样了.Import的内容 ...

最新文章

  1. python一个月能掌握吗_零基础python入门分析,如何做到一个月学会(深思极恐)...
  2. 阿里大鱼.net core 发送短信
  3. git cherry-pick命令
  4. VS中调试CS程序时提示:不支持互操作调试
  5. 第13天学习Java的笔记(类定义)
  6. 【NLP】word2vec中的数学模型
  7. python画饼图加牵引线_python-Matplotlib绘制分列式饼图并添加表格
  8. 【Java13】cookiesession(登陆案例(2)),jsp(登录案例(3))
  9. 虚拟机IP桥接与.net
  10. 一部珍贵的130位作家的手稿集
  11. Oracle10g数据库的树立
  12. 更换 CentOS 7 的下载源为阿里云
  13. 开源的WebKit 浏览器引擎受多个漏洞影响,可导致 RCE 后果
  14. Java锁示例– ReentrantLock
  15. 浅谈计算机是如何工作的及Linux下的简单反汇编操作
  16. 德国Taufenbach激光打标机电源维修RFE020详解
  17. 医院医疗类报表免费用,提反馈,还能赢取P30!
  18. shell的logo含义_华为logo的寓意是什么
  19. Python3之模块及包的导入 import用法
  20. JS根据函数名字符串调用函数

热门文章

  1. 在VMware Workstation 9中安装Mac OS X 10.8 Mountain Lion
  2. Opera 设置微软雅黑字体显示!
  3. [转载] Python 学习 - Numpy
  4. [转载] python 超高精度除法_Python十进制-除法,舍入,精度
  5. 二、将mysql用作一个简单的计算器
  6. LeetCode-C#实现-链表(#19/21/141/206/707/876)
  7. 构造函数_析构函数_深拷贝与浅拷贝
  8. 二叉树的基本操作(C)
  9. 【思维导图】nav_msgs/Odometry 消息的构成及订阅
  10. xbox360 ubuntu14.04连接问题