22.23.24.25.盒须图(boxplot)、棉棒图(Stem Plot; Lollipop plot)、极坐标图、雷达图(Radar Chart)

article/2025/8/27 2:48:51

22.盒须图(boxplot)
23.棉棒图(Stem Plot; Lollipop plot)
24.极坐标图
25.雷达图(Radar Chart)

22.盒须图(boxplot)

盒须图(也称为箱形图)是一种图表类型,通常用于说明性数据分析中,通过显示数据四分位数(或百分位数)和平均值来直观地显示数值数据的分布和偏度(skewness)。

箱形图于1977年由美国著名统计学家约翰·图基(John Tukey)发明。它能显示出一组数据的最大值、最小值、中位数、及上下四分位数。
在这里插入图片描述
最小值(minimum)
下四分位数(Q1)
中位数(Median,也就是Q2)
上四分位数(Q3)
最大值(maximum)
四分位间距(IQR)
箱形图将数据分为几个部分,每个部分包含该集中大约25%的数据。
在这里插入图片描述
请注意,上图代表的数据是完美的正态分布,大多数箱形图均不符合这种对称性(每个四分位数的长度相同)。
箱形图形状将显示统计数据集是正态分布还是偏斜。
在这里插入图片描述
在这里插入图片描述
箱形图很有用,因为它们显示了数据集中的异常值(outliers,离群值)。
离群值是在数值上与其余数据相距遥远的观测值。
查看箱形图时,离群值定义为位于箱形图whiskers之外的数据点。
在这里插入图片描述
在这里插入图片描述

import matplotlib
import matplotlib.pyplot as plt
import numpy as np# Fixing random state for reproducibility
np.random.seed(19680801)# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low))fig1, ax1 = plt.subplots()
ax1.set_title('Basic Plot')
ax1.boxplot(data)plt.show()

在这里插入图片描述

import matplotlib
import matplotlib.pyplot as plt
import numpy as np# Fixing random state for reproducibility
np.random.seed(19680801)# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low))fig2, ax2 = plt.subplots()
ax2.set_title('Notched boxes')
ax2.boxplot(data, notch=True)plt.show()

在这里插入图片描述

import matplotlib
import matplotlib.pyplot as plt
import numpy as np# Fixing random state for reproducibility
np.random.seed(19680801)# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low))green_diamond = dict(markerfacecolor='g', marker='D')
fig3, ax3 = plt.subplots()
ax3.set_title('Changed Outlier Symbols')
ax3.boxplot(data, flierprops=green_diamond)plt.show()

在这里插入图片描述

Fake up some more data

import matplotlib
import matplotlib.pyplot as plt
import numpy as np# Fixing random state for reproducibility
np.random.seed(19680801)# fake up some data
spread = np.random.rand(50) * 100
center = np.ones(25) * 50
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
data = np.concatenate((spread, center, flier_high, flier_low))spread = np.random.rand(50) * 100
center = np.ones(25) * 40
flier_high = np.random.rand(10) * 100 + 100
flier_low = np.random.rand(10) * -100
d2 = np.concatenate((spread, center, flier_high, flier_low))
data.shape = (-1, 1)
d2.shape = (-1, 1)plt.show()

在这里插入图片描述

23.棉棒图(Stem Plot; Lollipop plot)

棉棒图绘制从基线到y坐标的垂直线,并在尖端(tip)放置一个标记。

import matplotlib.pyplot as plt
import numpy as npx = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))plt.stem(x, y, use_line_collection=True)
plt.show()

在这里插入图片描述
基线的位置可以使用bottom进行调整。 参数linefmt,markerfmt和basefmt控制plot的基本格式属性。 但是,并非所有属性都可以通过关键字参数进行配置。 对于更高级的控制,可调整pyplot返回的线对象。

import matplotlib.pyplot as plt
import numpy as npx = np.linspace(0.1, 2 * np.pi, 41)
y = np.exp(np.sin(x))markerline, stemlines, baseline = plt.stem(x, y, linefmt='grey', markerfmt='D', bottom=1.1, use_line_collection=True)
plt.show()

在这里插入图片描述

import numpy as np
import pandas as pd
import matplotlib.pyplot as pltdf = pd.DataFrame({'Product':['Apple', 'Banana', 'Beer', 'Juice', 'Cheese','Coffee', 'Red wine', 'Hotdog'],'Turnover':[30, 59, 92, 43, 123, 93, 103, 37]},columns=['Product', 'Turnover'])
print(df)

输出结果:

    Product  Turnover
0     Apple        30
1    Banana        59
2      Beer        92
3     Juice        43
4    Cheese       123
5    Coffee        93
6  Red wine       103
7    Hotdog        37

在这里插入图片描述

import numpy as np
import pandas as pd
import matplotlib.pyplot as pltdf = pd.DataFrame({'Product':['Apple', 'Banana', 'Beer', 'Juice', 'Cheese','Coffee', 'Red wine', 'Hotdog'],'Turnover':[30, 59, 92, 43, 123, 93, 103, 37]},columns=['Product', 'Turnover'])
print(df)plt.figure(figsize=(9, 6))(markerline, stemlines, baseline) = plt.stem(df['Product'], df['Turnover'], use_line_collection=True)
plt.setp(markerline, marker='*', markersize=15, markeredgewidth=2, color='gold')
plt.setp(stemlines, color='gold')
plt.setp(baseline, visible=False)plt.tick_params(labelsize=12)
plt.xlabel('Product', size=12)
plt.ylabel('Turnover(k dollars)', size=12)
plt.ylim(bottom=0)plt.show()

在这里插入图片描述

该图描述了每种产品的营业额。 在八种产品中,奶酪的销售额带来了最大的营业额。

import pandas as pd
import matplotlib.pyplot as pltdf = pd.DataFrame({'Product':['Apple', 'Banana', 'Beer', 'Juice', 'Cheese','Coffee', 'Red wine', 'Hotdog'],'Turnover':[30, 59, 92, 43, 123, 93, 103, 37]},columns=['Product', 'Turnover'])
print(df)ordered_df = df.sort_values(by='Turnover').reset_index(drop=True)
my_range = range(1, len(df.index) + 1)plt.figure(figsize=(9, 6))plt.hlines(y=my_range, xmin=0, xmax=ordered_df['Turnover'], color='skyblue')
plt.plot(ordered_df['Turnover'], my_range, 'o', markersize=11)plt.yticks(ordered_df.index+1, ordered_df['Product'])
plt.tick_params(labelsize=12)
plt.xlabel('Turnover(k dollars)', size=12)
plt.ylabel('Product', size=12)
plt.xlim(left=0)plt.show()

在这里插入图片描述

24.极坐标图

调用subplot()创建子图时通过设置projection=’polar’,便可创建一个极坐标子图,然后调用plot()在极坐标子图中绘图。
在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt# 极坐标下需要的数据有极径和角度
r = np.arange(1, 6, 1)  # 极径
theta = [i * np.pi / 2 for i in range(5)]  # 角度# 指定画图坐标为极坐标,projection='polar'
ax = plt.subplot(111, projection='polar')
ax.plot(theta, r, linewidth=3, color='r')ax.grid(True)plt.show()

在这里插入图片描述

import numpy as np
import matplotlib.pyplot as plt# 极坐标参数设置
theta=np.arange(0,2*np.pi,0.02)
plt.figure(figsize=(8,4))
ax1= plt.subplot(121, projection='polar')
ax2= plt.subplot(122, projection='polar')
ax1.plot(theta,theta/6,'--',lw=2)
ax2.plot(theta,theta/6,'--',lw=2)
# 创建极坐标子图axax2.set_theta_direction(-1) # 坐标轴正方向改为顺时针
# set_theta_direction():坐标轴正方向,默认逆时针ax2.set_thetagrids(np.arange(0.0, 360.0, 90),['a','b','c','d'])
ax2.set_rgrids(np.arange(0.2,2,0.4))
# set_thetagrids():设置极坐标角度网格线显示及标签 → 网格和标签数量一致
# set_rgrids():设置极径网格线显示,其中参数必须是正数ax2.set_theta_offset(np.pi/2)
# set_theta_offset():设置角度偏移,逆时针,弧度制ax2.set_rlim(0.2,1.2)
ax2.set_rmax(2)
ax2.set_rticks(np.arange(0.1, 1.5, 0.2))
# set_rlim():设置显示的极径范围
# set_rmax():设置显示的极径最大值
# set_rticks():设置极径网格线的显示范围plt.show()

在这里插入图片描述

25.雷达图(Radar Chart)

雷达图是一种由一系列等角辐条(称为radii)组成的图表,每个辐条代表一个变量。 轮辐的数据长度与数据点变量的大小(magnitude )相对于所有数据点上变量的最大大小(maximum magnitude)成正比。 绘制一条线连接每个辐条的数据值。 这使该图块具有星形外观,并且是该图块的流行名称之一的起源。

适用时机:
比较两个或两个以上具有不同特征的items或groups。
检查一个个数据点的相对值。
在一张雷达图上显示少于十个因素。

没有内置函数允许使用Matplotlib制作雷达图。 因此,我们必须使用基本函数来构建它。

输入数据是pandas data frame,其中每行代表一个个体,每列代表一个变量。

import matplotlib.pyplot as plt
import pandas as pd
from math import pi# Set data
df = pd.DataFrame({'group': ['A', 'B', 'C', 'D'],'var1': [38, 1.5, 30, 4],'var2': [29, 10, 9, 34],'var3': [8, 39, 23, 24],'var4': [7, 31, 33, 14],'var5': [28, 15, 32, 14]
})# number of variable
categories = list(df)[1:]
N = len(categories)
print(N)# We are going to plot the first line of the data frame.
# But we need to repeat the first value to close the circular graph:
values=df.loc[0].drop('group').values.flatten().tolist()
values += values[:1]
print(values)# What will be the angle of each axis in the plot? (we divide the plot / number of variable)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]
print(angles)# Initialise the spider plot
ax = plt.subplot(111, polar=True)# Draw one axe per variable + add labels labels yet
plt.xticks(angles[:-1], categories, color='grey', size=8)# Draw ylabels
ax.set_rlabel_position(0)
plt.yticks([10, 20, 30], ["10", "20", "30"], color="grey", size=7)
plt.ylim(0, 40)# Plot data
ax.plot(angles, values, linewidth=1, linestyle='solid')# Fill area
ax.fill(angles, values, 'b', alpha=0.1)plt.show()

在这里插入图片描述

25.1.Radar chart with several individuals

# Libraries
import matplotlib.pyplot as plt
import pandas as pd
from math import pi# Set data
df = pd.DataFrame({'group': ['A', 'B', 'C', 'D'],'var1': [38, 1.5, 30, 4],'var2': [29, 10, 9, 34],'var3': [8, 39, 23, 24],'var4': [7, 31, 33, 14],'var5': [28, 15, 32, 14]
})# ------- PART 1: Create background# number of variable
categories = list(df)[1:]
N = len(categories)# What will be the angle of each axis in the plot? (we divide the plot / number of variable)
angles = [n / float(N) * 2 * pi for n in range(N)]
angles += angles[:1]# Initialise the spider plot
ax = plt.subplot(111, polar=True)# If you want the first axis to be on top:
ax.set_theta_offset(pi / 2)
ax.set_theta_direction(-1)# Draw one axe per variable + add labels labels yet
plt.xticks(angles[:-1], categories)# Draw ylabels
ax.set_rlabel_position(0)
plt.yticks([10, 20, 30], ["10", "20", "30"], color="grey", size=7)
plt.ylim(0, 40)# ------- PART 2: Add plots# Plot each individual = each line of the data
# I don't do a loop, because plotting more than 3 groups makes the chart unreadable# Ind1
values = df.loc[0].drop('group').values.flatten().tolist()
values += values[:1]
ax.plot(angles, values, linewidth=1, linestyle='solid', label="group A")
ax.fill(angles, values, 'b', alpha=0.1)# Ind2
values = df.loc[1].drop('group').values.flatten().tolist()
values += values[:1]
ax.plot(angles, values, linewidth=1, linestyle='solid', label="group B")
ax.fill(angles, values, 'r', alpha=0.1)# Add legend
plt.legend(loc='upper right', bbox_to_anchor=(0.1, 0.1))plt.show()

在这里插入图片描述

df = pd.DataFrame({'client_id': ['c1','c2','c3','c4'],'cheese': [2, 5, 4, 3],'beer': [2, 1, 3, 5],'chicken': [5, 3, 3, 4],'bread': [4, 3, 2, 1],'coffee': [2, 3, 5, 3]},columns=['client_id', 'cheese', 'beer', 'chicken', 'bread', 'coffee'])
df

在这里插入图片描述

# Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from math import pi# Set data
df = pd.DataFrame({'client_id': ['c1','c2','c3','c4'],'cheese': [2, 5, 4, 3],'beer': [2, 1, 3, 5],'chicken': [5, 3, 3, 4],'bread': [4, 3, 2, 1],'coffee': [2, 3, 5, 3]},columns=['client_id', 'cheese', 'beer', 'chicken', 'bread', 'coffee'])categories = list(df)[1:]values = df.mean().values.flatten().tolist()
values += values[:1] # repeat the first value to close the circular graphangles = [n / float(len(categories)) * 2 * pi for n in range(len(categories))]
angles += angles[:1]fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 8), subplot_kw=dict(polar=True))plt.xticks(angles[:-1], categories, color='grey', size=12)
plt.yticks(np.arange(1, 6), ['1', '2', '3', '4', '5'], color='grey', size=12)
plt.ylim(0, 5)
ax.set_rlabel_position(30)ax.plot(angles, values, linewidth=1, linestyle='solid')
ax.fill(angles, values, 'skyblue', alpha=0.4)plt.show()

在这里插入图片描述

该雷达图描述了4个客户的平均产品偏好。 chicken是最受欢迎的产品.

# Libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from math import pi# Set data
df = pd.DataFrame({'client_id': ['c1','c2','c3','c4'],'cheese': [2, 5, 4, 3],'beer': [2, 1, 3, 5],'chicken': [5, 3, 3, 4],'bread': [4, 3, 2, 1],'coffee': [2, 3, 5, 3]},columns=['client_id', 'cheese', 'beer', 'chicken', 'bread', 'coffee'])categories = list(df)[1:]values = df.mean().values.flatten().tolist()
values += values[:1] # repeat the first value to close the circular graphangles = [n / float(len(categories)) * 2 * pi for n in range(len(categories))]
angles += angles[:1]fig, ax = plt.subplots(nrows=1, ncols=1, figsize=(8, 8), subplot_kw=dict(polar=True))plt.xticks(angles[:-1], categories, color='grey', size=12)
plt.yticks(np.arange(1, 6), ['1', '2', '3', '4', '5'], color='grey', size=12)
plt.ylim(0, 5)
ax.set_rlabel_position(30)# part 1
val_c1 = df.loc[0].drop('client_id').values.flatten().tolist()
val_c1 += val_c1[:1]
ax.plot(angles, val_c1, linewidth=1, linestyle='solid', label='Client c1')
ax.fill(angles, val_c1, 'skyblue', alpha=0.4)# part 2
val_c2 = df.loc[1].drop('client_id').values.flatten().tolist()
val_c2 += val_c2[:1]
ax.plot(angles, val_c2, linewidth=1, linestyle='solid', label='Client c2')
ax.fill(angles, val_c2, 'lightpink', alpha=0.4)plt.legend(loc='upper right', bbox_to_anchor=(0.1, 0.1))plt.show()

在这里插入图片描述

该雷达图显示了4个客户中2个客户的偏好。客户c1喜欢鸡肉和面包,不那么喜欢奶酪。 但是,客户c2比其他4种产品更喜欢奶酪,并且不喜欢啤酒。


http://chatgpt.dhexx.cn/article/6x3M623D.shtml

相关文章

PS图片中字体或图像的颜色替换

第一步、打开替换颜色修改框。步骤:图像——调整——替换颜色 第二部、选择要替换的颜色 完后点确定,就可以修改好自己想要的颜色。

如何使用PS改变只有一种颜色图片的颜色

这里所说的图片是这种单色的图片 首先将这张图片拖到PS中打开,选择 图层 > 图层样式 > 颜色叠加 然后我们选择一种颜色 颜色改完了,保存。

ps修改图片的颜色

作为一个啥都要会的前端,有时候UI给了图,都是单色黑的,说需要什么颜色自己调,so: 1,新建一个200*200像素的画布(和图片一样大的画布) 2,将图片拖入画布 3,在右侧图层上双击,出现对话框 4,双击对话框左侧菜单…

PS修改图片的背景颜色(无需抠图)

1.复制图层,可以鼠标右键复制图层或CtrlJ复制图层 2.在菜单栏找到图像-->调整-->替换颜色,此时鼠标箭头变成了一个吸管的样子,去吸一下想要替换的颜色,然后选择要修改的颜色即可 具体如下操作:

不是美工,如何使用ps快速更换图标icon的颜色?

最近做个项目,美工撂挑子不干了,需要处理一个icon的颜色,怎么办呢?关键时刻只有靠自己了,自己上手。 使用ps就是简单,把制作方法分享给大家,欢迎留言讨论,自己也做个备忘。 目 录…

ps修改图片中的文字、数字

刚才学习修改ps图片中的文字,找到知乎这位博主写的,很详细,下面转载一下!! https://zhuanlan.zhihu.com/p/134102174 以下内容,是根据视频教程边学习,边做的笔记ヾ(o◕∀◕)ノヾ 讲…

PS如何修改图片日期或者其他文本内容

Spraing※boy作为一个修图软件,PS的功能强大到毫无人性,我也在逐渐探索这个神器,奢望着有一天能够征服它,给自己也P上黄金万两。这篇博客我们主要来探索一下PS如何修改图片上的日期或者其他的文本内容。 准备阶段:PS软…

ps改变图片色调

作u3d,还要稍微会一点ps的东西。 要改变图片文字或者其他整块颜色块的的颜色,首先 然后第二步: 减去多余的选区 最后,用油漆桶涂上其他颜色

ps改变图片的颜色

用PS打开图片选中你要改变颜色的区域,然后点击:图像-调整-颜色替换 然后选中中间的吸管,随意吸一个你所选区域,再调整色相,饱和度,明度 转载于:https://www.cnblogs.com/ccpblo/p/7009395.html

ps修改图片中的图片尺寸

今天有个小需求,需要修改图片中一个小icon的大小,统一修改为32*32 简单自学了一下ps,把方法分享给大家。 需要修改的图片文件为: 把icon修改为32*32尺寸大小。 ps具体操作如下: 1.使用ps打开需要修改的png文件&…

如何使用PS修改图片背景

(1)使用PS打开图片,使用魔法棒选中整个图片,然后点击空白处,右键选择反选,点击“选择反向” (2)点击反选后,再次点击“通过拷贝的图层”。 (3)删除…

PS CC 2015 修改图片颜色和大小

为什么修改图片颜色? 【预期:】设计师给的设计稿两种颜色的图片,图片尺寸要求是48x48像素,一张绿色,一张白色。 【实际】绿色图片符合要求,白色图片是40x40像素,偏小。测试妹子不干了&#xff0…

【Photoshop 教程系列第 1 篇】如何用 PS 给图片添加文字,修改文字的字体,大小和颜色

这是【Photoshop 教程系列第 1 篇】,如果觉得有用的话,欢迎关注专栏。 以 Photoshop 2021 为例。 首先导入一张图片,选择 【文字工具】,根据下图所示选择自己想要的字体、文字大小和颜色,然后将光标定在图片中某一位…

矩阵乘法的性质和矩阵的幂、转置,逆

矩阵乘法的性质和矩阵的幂 矩阵乘法的性质矩阵的幂矩阵的转置逆矩阵齐次线性方差组的解 矩阵乘法的性质 矩阵的幂 矩阵的转置 逆矩阵 齐次线性方差组的解 AX0 增广矩阵 行最简形势 如果非零行的数量小于未知数的数量,则有无数个解

矩阵和矩阵转置

一.矩阵乘 1.老师的代码 1.结构体 typedef struct TwoDArray{int rows;int columns;int **elements; }*TwoDArrayPtr;typedef struct TwoDStaticArray{int rows;int columns;int elements[ROWS][COLUMNS]; }*TwoDStaticArrayPtr; 2.初始化 TwoDArrayPtr initTwoDArray(int …

023 A转置矩阵=A的性质(三大性质)

A转置矩阵A的性质(三大性质)

矩阵转置相关公式_线性代数入门——矩阵的转置运算及对称矩阵的概念

系列简介:这个系列文章讲解线性代数的基础内容,注重学习方法的培养。线性代数课程的一个重要特点(也是难点)是概念众多,而且各概念间有着千丝万缕的联系,对于初学者不易理解的问题我们会不惜笔墨加以解释。在内容上,以国内的经典教材“同济版线性代数”为蓝本,并适当选取…

逆矩阵和转置矩阵的基本性质

1 逆矩阵 设A是一个n阶矩阵,若存在另一个n阶矩阵B,使得: ABBAE ,则称方阵A可逆,并称方阵B是A的逆矩阵 [1]。 2 转置矩阵 将矩阵的行列互换得到的新矩阵称为转置矩阵,转置矩阵的行列式不变。 参考链接&am…

矩阵的基本性质【转置/求逆/伴随等】

速查目录 转置 A T A^T AT共轭矩阵共轭转置 A H A^H AH满秩分解的求法线性空间内积施密特正交化方法 转置 A T A^T AT ( A B ) T A T B T (A\pm B)^TA^T\pm B^T (AB)TATBT ( A B ) T B T A T (AB)^TB^TA^T (AB)TBTAT ( A T ) T A (A^T)^TA (AT)TA ( K A ) T K A T (KA)^…

4.9-4.10 矩阵乘法的性质 矩阵的幂运算 矩阵的转置及其性质

矩阵乘法的性质 矩阵的乘法不遵守交换律 ! 矩阵乘法遵守结合律、分配律 对于任意r行c列的矩阵A,存在c行x列的矩阵O,满足:A . Ocx Orx 对于任意r行c列的矩阵A,存在x行r列的矩阵O,满足:Oxr . A …