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 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:
输入数据集:
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.
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:
输入数据集:
Output:
输出:
与线图一起使用不同的调色板 (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.
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:
输出:
误差线添加到线图 (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:
输出:
使用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:
输出:
结论 (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 Documentation Seaborn线图—官方文档