📜  如何在 Linux 上安装 Seaborn?

📅  最后修改于: 2022-05-13 01:57:03.792000             🧑  作者: Mango

如何在 Linux 上安装 Seaborn?

Seaborn是一个主要用于Python中的统计绘图的库。它建立在 Matplotlib 之上,并提供漂亮的默认样式和调色板,使统计图更具吸引力。

Seaborn 依赖项:

Seaborn 具有以下依赖项:

  • Python 3.4+
  • 麻木的
  • scipy
  • 熊猫
  • matplotlib
  • 点子

在 Linux 上安装 Seaborn:

在终端中使用以下命令安装 Seaborn:

pip install seaborn

在终端中,它将如下所示:

在 linux 中安装 seaborn

安装完成后你会在终端最后看到安装成功的信息,如下图:

在linux中成功安装seaborn

安装后,让我们看一个使用 Seaborn 的简单绘图示例。我们将使用 iris 数据集绘制一个简单的线图。鸢尾花数据集包含花瓣长度、花瓣宽度、萼片长度、萼片宽度和物种类型等五列。鸢尾是一种开花植物,研究人员测量了不同鸢尾花的各种特征,并以数字方式记录下来。

例子:

Python3
# importing packages
import seaborn as sns
 
# loading dataset
data = sns.load_dataset("iris")
 
# draw lineplot
sns.lineplot(x="sepal_length", y="sepal_width", data=data)


Python3
# Python program to illustrate
# Plotting categorical scatter
# plots with Seaborn
 
# importing the required module
import matplotlib.pyplot as plt
import seaborn as sns
 
# x axis values
x =['sun', 'mon', 'fri', 'sat', 'tue', 'wed', 'thu']
 
# y axis values
y =[5, 6.7, 4, 6, 2, 4.9, 1.8]
 
# plotting strip plot with seaborn
ax = sns.stripplot(x, y);
 
# giving labels to x-axis and y-axis
ax.set(xlabel ='Days', ylabel ='Amount_spend')
 
# giving title to the plot
plt.title('My first graph');
 
# function to show plot
plt.show()



输出:

在上面的示例中,使用 lineplot() 方法创建了一个简单的线图。

示例 2:使用 Seaborn 使用 Matplotlib 绘制分类散点图。

Python3

# Python program to illustrate
# Plotting categorical scatter
# plots with Seaborn
 
# importing the required module
import matplotlib.pyplot as plt
import seaborn as sns
 
# x axis values
x =['sun', 'mon', 'fri', 'sat', 'tue', 'wed', 'thu']
 
# y axis values
y =[5, 6.7, 4, 6, 2, 4.9, 1.8]
 
# plotting strip plot with seaborn
ax = sns.stripplot(x, y);
 
# giving labels to x-axis and y-axis
ax.set(xlabel ='Days', ylabel ='Amount_spend')
 
# giving title to the plot
plt.title('My first graph');
 
# function to show plot
plt.show()

输出:

这里,

  • 分类数据在 x 轴上表示,值对应于通过 y 轴表示的数据。
  • .striplot()函数用于定义绘图的类型并将它们绘制在画布上使用。
  • .set()函数用于设置 x 轴和 y 轴的标签。
  • .title()函数用于为图形赋予标题。
  • 要查看绘图,我们使用.show()函数。