Seaborn barplot 教程(以条形图可视化您的数据)

2023-10-18

数据可视化已成为与分析数据进行交流的重要阶段。通过数据可视化,数据科学家和业务分析师可以轻松地从大量数据中提取见解。

Seaborn 是一种 Python 中的统计图形绘图和可视化库,允许数据分析师和数据科学专业人员呈现可视化。

在本文中,我们将讨论如何通过强大的seaborn库创建和处理条形图。

 

 

什么是条形图?

条形图或条形图是最突出的可视化图之一,用于以图形格式描述统计和数据驱动的操作。

统计学家和工程师用它来显示数字变量和分类变量之间的关系。

分类变量的所有实体都以条形的形式表示。条形大小代表数值。

 

来自 DataFrame 的 Seaborn 条形图

我们可以使用Pandas 的数据框用于可视化seaborn中的数据。为此,我们必须导入三个模块:Pandas、Matplotlib和海生。这是显示如何使用它的代码片段。


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
#creating dataframe
df = pd.DataFrame({
    'Name':list("QWERTYUI"),
    'Student IDs': list(range(12001,12009)),
    'Yearly Progress':list('ABCDABCD'),
    'Chemistry': [59,54,42,66,60,78,64,82],
    'Physics': [90,42,88,48,80,73,43,69],
    'Math': [45,85,54,64,72,64,67,70]
})
df_detailed = pd.melt(df, id_vars=['Name', 'Student IDs', 'Yearly Progress'], value_vars=['Chemistry', 'Physics', 'Math'])
ax = sns.barplot(x = "Yearly Progress", y = "value", hue = "variable", data = df_detailed)
plt.show()  

Output

从列表创建条形图

我们还可以使用一个充满数据的简单列表来使用 seaborn 生成条形图,而不是使用 Pandas DataFrame。这是一个代码片段,展示了如何使用它。


import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
raw_data1 = [[127.66773437098896, 47.585408826566024, 90.426437828641106, 414.955787935926836],
           [147.700582993718115, 37.59796443553682, 245.38896827262796, 312.80916093973529],
           [123.66563311651776, 177.476571906259835, 145.21460968763448, 54.78683755963528],
           [47.248523637295705, 67.42573841363118, 145.52890109500238, 211.10243082784969],
           [148.14532745960979, 87.46958795222966, 67.4804195003332, 68.97715435208194],
           [46.61620129160194, 224.316775886868584, 138.053032014046366, 41.527497508033704]]
def plot_sns(raw_data):
  data = np.array(raw_data)
  x = np.arange(len(raw_data))
  sns.axes_style('white')
  sns.set_style('white')
  ax = sns.barplot(x, data[:,0])
  plt.show()

plot_sns(raw_data1)  

Output

 

显示值

在条形图上或条形内显示各个值是使用 seaborn 条形图的另一种重要方式。

我们可以使用带有一些属性的 annotate() 来设置标签发生的位置。下面是一个代码片段,展示了如何通过DataFrame整体实现它。


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
continent_data = ["Asia", "America", "Africa", "Oceania", "Europe"]
lifeExpectancy = [87, 63, 77, 56, 39]

dataf = pd.DataFrame({"continent_data":continent_data, "lifeExpectancy":lifeExpectancy})
plt.figure(figsize = (9, 7))
splot = sns.barplot(x = "continent_data", y = "lifeExpectancy", data=dataf)
for g in splot.patches:
    splot.annotate(format(g.get_height(), '.1f'),
                   (g.get_x() + g.get_width() / 2., g.get_height()),
                   ha = 'center', va = 'center',
                   xytext = (0, 9),
                   textcoords = 'offset points')
plt.xlabel("Continent Names", size = 14)
plt.ylabel("Life Expectancy", size = 14)
plt.show()  

Output


We can also provide the value within the bars in the barplot. To do this we have to simply set the xytext attribute to (0, -12), which means the y value of the attribute will go downward because of the negative value set for it. In this case, the code will be:


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
continent_data = ["Asia", "America", "Africa", "Oceania", "Europe"]
lifeExpectancy = [87, 63, 77, 56, 39]

dataf = pd.DataFrame({"continent_data":continent_data, "lifeExpectancy":lifeExpectancy})
plt.figure(figsize = (9, 7))
splot = sns.barplot(x = "continent_data", y = "lifeExpectancy", data=dataf)
for g in splot.patches:
    splot.annotate(format(g.get_height(), '.1f'),
                   (g.get_x() + g.get_width() / 2., g.get_height()),
                   ha = 'center', va = 'center',
                   xytext = (0, -13),
                   textcoords = 'offset points')
plt.xlabel("Continent Names", size = 14)
plt.ylabel("Life Expectancy", size = 14)
plt.show()  

Output

更改条形图的颜色

有多种方法可以更改默认箱线图的颜色。我们可以使用 barplot() 的 color 属性将它们全部更改为新颜色。

我们还可以通过列表手动设置调色板值或使用已经使用seaborn创建的默认调色板颜色集。以下代码片段展示了如何将所有条形更改为单一颜色。


import matplotlib.pyplot as plt
import seaborn as sns
x = ['A', 'B', 'C', 'D']
y = [1, 5, 3, 7]
sns.barplot(x, y, color = 'violet')
plt.show()  

Output


Again we can manually set colors for each bar using the palette parameter of the barplot(). We have to pass the color names within the list as palette values.


import matplotlib.pyplot as plt
import seaborn as sns
x = ['A', 'B', 'C', 'D']
y = [1, 5, 3, 7]
sns.barplot(x, y, color = 'blue', palette = ['tab:blue', 'tab:orange', 'tab:red', 'tab:green'])
plt.show()  

Output


Apart from manually providing the color values, we can also use predefined color palettes defined in the Seaborn color palettes. Here is how to use it.


import matplotlib.pyplot as plt
import seaborn as sns
x = ['A', 'B', 'C', 'D']
y = [1, 5, 3, 7]
sns.barplot(x, y, color = 'blue', palette = 'hls')
plt.show()  

Output

条件颜色

我们还可以对条形图值或数据设置特定条件,为它们设置不同的颜色或调色板。

以下代码片段展示了如何根据条件通过调色板设置不同的颜色。


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
continent_data = ["Asia", "America", "Africa", "Oceania", "Europe"]
lifeExpectancy = [99, 63, 77, 56, 27]
custom_palette = {}
dataf = pd.DataFrame({"continent_data":continent_data, "lifeExpectancy":lifeExpectancy})
plt.figure(figsize = (9, 7))
for q in lifeExpectancy:
    if q < 30 and q > 50:
        custom_palette[q] = 'Paired'
    elif q < 50 and q > 60:
        custom_palette[q] = 'PRGn'
    elif q < 60 and q > 70:
        custom_palette[q] = 'husl'
    else:
        custom_palette[q] = 'hls'
sns.barplot(x = "continent_data", y = "lifeExpectancy", data=dataf, palette=custom_palette[q])
plt.xlabel("Continent Names", size = 14)
plt.ylabel("Life Expectancy", size = 14)
plt.show()  

Output

 

水平条形图

我们可以使用 barplot() 生成水平条形图。它还将具有相同的功能和可视化能力;唯一的区别是,它们不是垂直放置(我们到目前为止已经遇到过),而是水平放置。


import seaborn as sns
import matplotlib.pyplot as plt
labels = ['C++', 'Python', 'Go', 'Ruby', 'JavaScript']
price = [50, 60, 90, 100, 150]
sns.barplot(x = price, y = labels)
plt.show()  

Output

 

放一个图例

数据可视化中的图例是存在于图表任意一角的小方框。它包含与表示绘图的某些元素类型的文本关联的多条颜色线。

当多个数据驻留在图表中时,图例中的指示表示哪个组件代表哪个数据。

Seaborn 将从 DataFrame 中获取字符串(键)作为图例标签。下面是一段代码片段,展示了seaborn如何生成一个。


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({'Scores': [24, 15, 17, 11, 16, 21, 24, 27],
                   'assists': [1, 8, 9, 12, 11, 6, 3, 1],
                   'Group': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B']})

sns.barplot(data = df, x = 'Scores', y = 'assists', hue = 'Group')
plt.legend(title = 'Group Category')
plt.show()
  

Output


We can also change the position of the Legend but not using seaborn. For such manipulation, we need to use the Matplotlib.pyplot’s legend() method loc parameter. We can also specify other location values to the loc:

  • 右上方
  • 左上
  • 左下角
  • 右下
  • right
  • 中左
  • 中右
  • 下中心
  • 上中心
  • center

import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({'Scores': [24, 15, 17, 11, 16, 21, 24, 27],
                   'assists': [1, 8, 9, 12, 11, 6, 3, 1],
                   'Group': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B']})

sns.barplot(data = df, x = 'Scores', y = 'assists', hue = 'Group')
plt.legend(loc = 'center right', title = 'Group Category')
plt.show()  

Output

删除图例

有两种不同的方法可以从seaborn 的可视化中删除图例。这些都是:

Method 1:使用 matplotlib.pyplot.legend():我们可以使用 matplotlib.pyplot.legend() 函数向 seaborn 图中添加自定义图例。

我们可以使用 matplotlib.pyplot 中的 legend(),因为 Seaborn 运行在 matplotlib 模块之上,因此很容易操纵 Seaborn 操作和可视化。

要删除图例,我们必须向图中添加一个空图例并删除其框架。它将有助于隐藏最终图形中的图例。


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({'Scores': [24, 15, 17, 11, 16, 21, 24, 27],
                   'assists': [1, 8, 9, 12, 11, 6, 3, 1],
                   'Group': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B']})

sns.barplot(data = df, x = 'Scores', y = 'assists', hue = 'Group')
plt.legend([],[], frameon=False)
plt.show()  

Output

Method 2:使用remove():我们还可以使用legend_.remove()从图中删除图例。


import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
df = pd.DataFrame({'Scores': [24, 15, 17, 11, 16, 21, 24, 27],
                   'assists': [1, 8, 9, 12, 11, 6, 3, 1],
                   'Group': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B']})

gk = sns.barplot(data = df, x = 'Scores', y = 'assists', hue = 'Group')
gk.legend_.remove()
plt.show()  

Output

 

添加标签

我们经常需要标记 x 轴和 y 轴,以便更好地指示或赋予绘图含义。要在图中设置标签,有两种不同的方法。这些都是:
Method 1:使用 set() 方法:第一种方法是使用 set() 方法并将字符串作为标签传递给 xlabel 和 ylabel 参数。这是一个代码片段,展示了我们如何执行此操作。


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
datf = pd.DataFrame({"Season 1": [7, 4, 5, 6, 3],
                 "Season 2" : [1, 2, 8, 4, 9]})
p = sns.barplot(data = datf)
p.set(xlabel="X Label Value", ylabel = "Y Label Value")
plt.show()  

Output


Method 2: Using matplotlib’s xlabel() and ylabel(): Since seaborn runs on top of Matplotlib, we can use the Matplotlib methods to set the labels for the x and y axes. Here is a code snippet showing how can we perform that.


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
datf = pd.DataFrame({"Season 1": [7, 4, 5, 6, 3],
                 "Season 2" : [1, 2, 8, 4, 9]})
p = sns.barplot(data = datf)
plt.xlabel('X axis labeling')
plt.ylabel('Y axis labeling')
plt.show()  

Output

 

更改条形宽度

默认情况下,seaborn 中的条形图不提供显式参数来更改条形宽度。但我们可以编写并添加一个单独的函数来执行此操作。


import pylab as plt
import seaborn as sns
tips = sns.load_dataset("tips")
fig, axi = plt.subplots()
sns.barplot(data = tips, ax = axi, x = "time", y = "tip", hue = "sex")
def width_changer(axi, new_value):
    for patch in axi.patches :
        cur_width = patch.get_width()
        diff = cur_width - new_val
        patch.set_width(new_val)
        patch.set_x(patch.get_x() + diff * .5)
plt.legend(loc = 'upper right', title = 'Gender')
width_changer(axi, .18)
plt.show()
  

Output

 

设置图形大小

在seaborn中设置绘图的图形大小有不同的方法。一些众所周知的方法是:
Method 1:seaborn.set():

此方法有助于控制seaborn 图的组成和配置。我们可以设置rc参数并传递图形大小属性来设置seaborn图的图形大小。

这是显示如何使用它的代码片段。


import pylab as plt
import seaborn as sns
tips = sns.load_dataset("tips")
fig, axi = plt.subplots()
sns.set(rc = {'figure.figsize':(12.0,8.5)})
sns.barplot(data = tips, ax = axi, x = "time", y = "tip", hue = "sex")
def width_changer(axi, new_val):
    for patch in axi.patches :
        cur_width = patch.get_width()
        diff = cur_width - new_val
        patch.set_width(new_val)
        patch.set_x(patch.get_x() + diff * .5)
plt.legend(loc = 'upper right', title = 'Gender')
width_changer(axi, .18)
plt.show()  

Output


Method 2: matplotlib.pyplot.figure(): We can also use the matplotlib.pyplot.figure() and use the figsize parameter to pass two values as Tuple. The code snippet will look something like this.


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib import rcParams

datf = pd.DataFrame({"Season 1": [7, 4, 5, 6, 3],
                 "Season 2" : [1, 2, 8, 4, 9]})
plt.figure(figsize = (14, 7))
p = sns.barplot(data = datf)
plt.legend(loc = 'center', title = 'Karlos TV series')
plt.show()  

Output


Method 3: Using rcParams: We can also use the rcParams, which is a part of the Matplotlib library to control the style and size of the plot. It works similar to the seaborn.set(). Here is a code snippet showing how to use it.


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from matplotlib import rcParams

datf = pd.DataFrame({"Season 1": [7, 4, 5, 6, 3],
                 "Season 2" : [1, 2, 8, 4, 9]})
rcParams['figure.figsize'] = 14, 7
p = sns.barplot(data = datf)
plt.legend(loc = 'center', title = 'Karlos TV series')
plt.show()  

Output


Method 4: matplotlib.pyplot.gcf(): This function helps in getting the instance of the current figure. Along with the gcf() instance, we can use the set_size_inches() method to modify the final size of the seaborn plot. The code snippet will look something like this.


import pylab as plt
import seaborn as sns
tips = sns.load_dataset("tips")
fig, axi = plt.subplots()
sns.barplot(data = tips, ax = axi, x = "time", y = "tip", hue = "sex")
def width_changer(axi, new_val):
    for patch in axi.patches :
        cur_width = patch.get_width()
        diff = cur_width - new_val
        patch.set_width(new_val)
        patch.set_x(patch.get_x() + diff * .5)
plt.gcf().set_size_inches(14, 7)
plt.legend(loc = 'upper right', title = 'Gender')
width_changer(axi, .18)
plt.show()  

Output

 

设置字体大小

在通过seaborn 创建可视化效果时,字体大小起着重要作用。有两种不同的方法可以设置可视化的字体大小。这些都是:
Method 1:使用 fontsize 参数:我们可以将此参数与多个 matplotlib 方法一起使用,例如 xlabel()、ylabel()、title() 等。下面是一个代码片段,展示如何利用它们。


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
datf = pd.DataFrame({'dor': ['1/12/2022', '1/30/2022', '2/27/2022', '2/28/2022'],
                   'marketReach': [7, 12, 5, 16],
                   'Brand': ['A', 'A', 'B', 'B']})

sns.barplot(x = 'dor', y = 'marketReach', hue = 'Brand', data = datf)
plt.legend(title = 'Brand Name', fontsize=20)
plt.xlabel('Date of Release', fontsize = 15);
plt.ylabel('Market Reach', fontsize = 15);
plt.title('Overall Sales Report', fontsize = 22)
plt.tick_params(axis='both', which='major', labelsize=12)
plt.show()  

Output


Method 2: Using the set() method: Another way to set the font size for all the fonts associated with the plot is using the set() method of the Seaborn. Here’s how to use it.


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

datf = pd.DataFrame({'dor': ['1/12/2022', '1/30/2022', '2/27/2022', '2/28/2022'],
                   'marketReach': [7, 12, 5, 16],
                   'Brand': ['A', 'A', 'B', 'B']})
sns.set(font_scale = 3)
sns.barplot(x = 'dor', y = 'marketReach', hue = 'Brand', data = datf)
plt.legend(title = 'Brand Name', fontsize=20)
plt.show()  

Output

 

条形之间的空间

我们可以通过两种不同的方法在酒吧之间创造空间。
Method 1:通过在连续条之间添加空白条:


import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
datf = pd.DataFrame({'Name': ['Karl', 'Ray', 'Sue', 'Dee'],
 'SalInLac': [25, 28, 21, 26], 'Gender': ['M', 'M', 'F', 'F']})
datf = pd.concat([datf[datf.Gender == 'M'],
pd.DataFrame({'Name': [''], 'SalInLac': [0], 'Gender': ['M']}), datf[datf.Gender == 'F']])
age_plot = sns.barplot(data = datf, x = "Name", y = "SalInLac", hue="Gender", dodge=False)
plt.setp(age_plot.get_xticklabels(), rotation=90)
plt.ylim(0, 45)
age_plot.tick_params(labelsize = 6)
age_plot.tick_params(length = 4, axis='x')
age_plot.set_ylabel("Age", fontsize=12)
age_plot.set_xlabel("", fontsize=1.5)
plt.tight_layout()
plt.show()  

Output


Method 2: By creating spaces in the label names:


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns

datf = pd.DataFrame({'val': ['    Val1    ', '   Val2   ', '     Val3    ', '    Val4   '],
                   'marketReach': [7, 12, 5, 16],
                   'Brand': ['A', 'A', 'B', 'B']})
sns.set(font_scale = 1)
sns.barplot(x = 'val', y = 'marketReach', hue = 'Brand', data = datf)
plt.legend(title = 'Brand Name', fontsize=20)
plt.show()  

Output

 

垂直旋转轴刻度级别

通过调整刻度标签有两种不同的旋转轴的方法。
Method 1:使用 xticks() 方法:matplotlib.pyplot.xticks() 函数中可用的旋转参数可以帮助实现此目的。这是有关如何使用它的代码片段。


import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
datf = pd.DataFrame({'Name': ['Karl', 'Ray', 'Sue', 'Dee'], 'SalInLac': [25, 28, 21, 26], 'Gender': ['M', 'M', 'F', 'F']})
datf = pd.concat([datf[datf.Gender == 'M'], pd.DataFrame({'Name': [''], 'SalInLac': [0], 'Gender': ['M']}), datf[datf.Gender == 'F']])
age_plot = sns.barplot(data = datf, x = "Name", y = "SalInLac", hue="Gender", dodge=False)
plt.setp(age_plot.get_xticklabels(), rotation=90)
plt.ylim(0, 45)
age_plot.tick_params(labelsize = 10)
age_plot.tick_params(length = 4, axis='x')
age_plot.set_ylabel("Age", fontsize=12)
age_plot.set_xlabel("", fontsize=1.5)
plt.tight_layout()
plt.xticks(rotation = 45)
plt.show()  

Output


Method 2: using setp() method: The set parameter setp() method also enables us to rotate the x-axis tick-levels. Here is the code snippet on how to use it.


import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
datf = pd.DataFrame({'Name': ['Karl', 'Ray', 'Sue', 'Dee'], 'SalInLac': [25, 28, 21, 26], 'Gender': ['M', 'M', 'F', 'F']})
datf = pd.concat([datf[datf.Gender == 'M'], pd.DataFrame({'Name': [''], 'SalInLac': [0], 'Gender': ['M']}), datf[datf.Gender == 'F']])
age_plot = sns.barplot(data = datf, x = "Name", y = "SalInLac", hue="Gender", dodge=False)
plt.setp(age_plot.get_xticklabels(), rotation=90)
plt.ylim(0, 45)
age_plot.tick_params(labelsize = 10)
age_plot.tick_params(length = 4, axis='x')
age_plot.set_ylabel("Age", fontsize=12)
age_plot.set_xlabel("", fontsize=1.5)
plt.tight_layout()
locs, labels = plt.xticks()
plt.setp(labels, rotation = 45)
plt.show()  

Output

 

绘制多个/分组条形图

我们可以在 Seaborn 中对多个条形图进行分组,并将它们显示在一个图下。这是显示如何使用它的代码片段。


import seaborn as sns
import matplotlib.pyplot as plt
tips = sns.load_dataset("tips")
colors = ["#69d", "#69b3a2"]
sns.set_palette(sns.color_palette(colors))
plt.figure(figsize = (9, 8))

# multiple barplot grouped together
ax = sns.barplot(
    x = "day",
    y = "total_bill",
    hue = "smoker",
    data = tips,
    ci=None
    )
ax.set_title("Smokers with large bills")
ax.set_ylabel("Expense")
plt.show()  

Output

 

对 Seaborn 条形图进行排序

我们可以使用 sort_values() 方法对 Seaborn 条形图中的条形进行排序,并传递排序所依据的对象。

另外,我们必须将 ascending 参数设置为 True 或 False 来确定是否按升序或降序显示排序条形图。

下面是一个代码片段,展示了如何在 seaborn.barplot() 中使用它。


import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
CompanyLocations = ["Delhi", "Mumbai", "Madhya Pradesh",
         "Hyderabad", "Bangaluru"]
CompanyProfit = [644339, 780163, 435245, 256079, 805463]
datf = pd.DataFrame({"CompanyLocations": CompanyLocations,
                   "CompanyProfit": CompanyProfit})
# make barplot and sort bars
sns.barplot(x='CompanyLocations',
            y="CompanyProfit", data = datf,
            order = datf.sort_values('CompanyProfit',ascending = False).CompanyLocations)
plt.show()  

Output


If we want to show it in ascending order, we have to simply set the ascending = True


sns.barplot(x='CompanyLocations',
            y="CompanyProfit", data = datf,
            order = datf.sort_values('CompanyProfit',ascending = True).CompanyLocations)  

Output

 

结论

我们希望本文能够全面介绍什么是seaborn条形图以及如何使用seaborn创建条形图、创建条件、包含和排除图例、设置图形大小、字体和标签。

我们还收集了有关如何更改与 barplot() 相关的各种配置的见解和编程经验。

由于seaborn barplot在数据可视化和数据分析绘制图表中非常重要,因此我们应该充分理解它。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Seaborn barplot 教程(以条形图可视化您的数据) 的相关文章

随机推荐

  • 如何在 Ubuntu 20.04 上安装 Ruby

    Ruby 是动态的开源编程语言 其重点是编码简单性和提高生产力 第一个 Ruby 版本 0 95 于 1995 年发布 此后 在过去几年中发布了几个稳定的 Ruby 版本 在撰写本教程时 Ruby 2 7 0 是可用于开发的最新稳定版本 本
  • OpenSSL:使用 SSL 证书、私钥和 CSR

    OpenSSL 是一个强大的 功能齐全的开源工具包 它实现了 SSL 和 TLS 协议以及通用加密库 它广泛用于管理各种系统中的 SSL TLS 证书 私钥和证书签名请求 CSR 在本文中 我们将探讨如何使用 OpenSSL 来处理 SSL
  • 如何通过 PPA 在 Ubuntu 18.04 和 16.04 上安装 Libreoffice 6.2

    LibreOffice 6 2 已发布并可在官方向后移植 PPA用于 Ubuntu 系统上的安装 它是一款免费的办公套件应用程序 与以前的版本相比有许多增强功能 它包含了许多有用的功能 使办公室管理变得非常容易 它是专门针对 Linux 桌
  • 使用 Python 函数

    在编程时 我们经常重复执行相同的任务 例如执行数字加法或使用不同的输入打印相同的语句 这些是一般示例 但对于这些示例 您愿意编写相同的代码 10 次还是只编写一次 这就是函数的目的 它们是仅针对特定任务定义一次的代码片段 并具有可重用的功能
  • 在 HDFS 中创建目录并复制文件 (Hadoop)

    HDFS is the Hadoop分布式文件系统 它是一个用于大型数据集的分布式存储系统 支持容错 高吞吐量和可扩展性 它的工作原理是将数据划分为在集群中的多台机器上复制的块 这些块可以并行写入或读取 从而提高吞吐量和容错能力 HDFS
  • 如何在 Debian 11/10/9 上安装 Gulp.js

    Gulp是一个工具包 可帮助开发人员在开发过程中实现痛苦工作流程的自动化 本教程将帮助您在 Debian 11 Debian 10 和 Debian 9 操作系统上安装 Gulp 第 1 步 安装 Node js 首先 你需要安装node
  • 如何在 Linux 中递归更改文件的权限

    如果您使用 Linux 作为主要操作系统或管理 Linux 服务器 您会遇到尝试创建或编辑文件并收到 权限拒绝 错误的情况 通常 与权限不足相关的错误可以通过设置正确的文件权限或所有权 Linux 是一个多用户系统 对文件的访问是通过文件权
  • 如何显示 MySQL 中所有数据库的列表

    给药时MySQL对于数据库服务器 您要做的最常见的任务之一就是熟悉环境 这涉及诸如列出驻留在服务器上的数据库等任务 显示表格特定数据库的信息或获取有关用户帐户及其权限的信息 本教程介绍如何通过命令行显示 MySQL 或 MariaDB 服务
  • 如何创建 Tar Gz 文件

    tar 存档是一个存储其他文件集合的文件 包括有关这些文件的信息 例如所有权 权限和时间戳 在 Linux 操作系统中 您可以使用tar创建 tar 档案的命令 该命令还可以使用各种压缩程序来压缩档案 其中 gzip 是最流行的算法 按照约
  • 如何在 Ubuntu 20.04 上安装 GCC (build-essential)

    GNU 编译器集合 GCC 是 C C Objective C Fortran Ada Go D 编程语言 很多开源项目 包括Linux内核和GNU工具 都是使用GCC编译的 本文介绍如何在 Ubuntu 20 04 上安装 GCC 在 U
  • 如何在 Debian 9 上安装和使用 FFmpeg

    FFmpeg 是一个免费的开源命令行工具 用于对多媒体文件进行转码 它包含一组共享的音频和视频库 例如libavcodec libavformat和libavutil 使用 FFmpeg 您可以在各种视频和音频格式之间进行转换 设置采样率以
  • 如何在 Ubuntu 18.04 上安装 Python 3.7

    Python 是世界上最流行的编程语言之一 凭借其简单易学的语法 Python 是初学者和经验丰富的开发人员的绝佳选择 Python 是一种非常通用的编程语言 它可以用作脚本语言来构建游戏 开发网站 创建机器学习算法和分析数据 Python
  • 如何在 CentOS 7 上安装 VLC 媒体播放器

    VLC 是一种流行的开源多媒体播放器和流媒体服务器 它是跨平台的 几乎可以播放所有多媒体文件以及 DVD 音频 CD 和不同的流媒体协议 本教程介绍如何在 CentOS 7 上安装 VLC 媒体播放器 先决条件 您需要以以下身份登录具有 s
  • 如何在 Ubuntu 20.04 上安装和使用 FFmpeg

    FFmpeg 是一个用于处理多媒体文件的免费开源工具集合 它包含一组共享的音频和视频库 例如libavcodec libavformat和libavutil 使用 FFmpeg 您可以在各种视频和音频格式之间进行转换 设置采样率 捕获流音频
  • Linux 睡眠命令(暂停 Bash 脚本)

    sleep是一个命令行实用程序 允许您将调用进程挂起指定的时间 换句话说 sleep命令将下一个命令的执行暂停给定的秒数 The sleep该命令在 bash shell 脚本中使用时非常有用 例如 在重试失败的操作或在循环内时 在本教程中
  • 如何在 Ubuntu 18.04 上安装 CouchDB

    CouchDB 是由 Apache 软件基金会维护的免费开源容错 NoSQL 数据库 CouchDB 服务器将其数据存储在命名数据库中 其中包含以下文档JSON结构 每个文档由许多字段和附件组成 字段可以包括文本 数字 列表 布尔值等 它包
  • 如何在 Debian 10 上安装 Xrdp 服务器(远程桌面)

    Xrdp 是 Microsoft 远程桌面协议 RDP 的开源实现 允许您以图形方式控制远程系统 使用 RDP 您可以登录到远程计算机并创建真实的桌面会话 就像登录到本地计算机一样 本教程介绍如何在 Debian 10 Linux 上安装和
  • 如何使用SFTP命令传输文件

    SFTP SSH 文件传输协议 是一种安全文件协议 用于通过加密的 SSH 传输访问 管理和传输文件 与传统的相比FTPSFTP 提供 FTP 的所有功能 但更安全且更易于配置 Unlike SCPSFTP 仅支持文件传输 但允许您对远程文
  • 15+ yum update 命令示例

    Yum 是 Red Hat CentOS 和其他操作系统上使用的包管理器Linux 发行版使用 RPM 包管理器 Yum 用于安装 更新 删除或以其他方式操作这些 Linux 系统上安装的软件包 在本教程中 我们将介绍 yum update
  • Seaborn barplot 教程(以条形图可视化您的数据)

    数据可视化已成为与分析数据进行交流的重要阶段 通过数据可视化 数据科学家和业务分析师可以轻松地从大量数据中提取见解 Seaborn 是一种 Python 中的统计图形绘图和可视化库 允许数据分析师和数据科学专业人员呈现可视化 在本文中 我们