mtalab箱线图画法
时间: 2023-09-23 19:10:05 浏览: 61
箱线图在Matlab中可以使用boxplot函数来制作。可以通过以下两种方式进行绘制:
代码1:
import matplotlib.pyplot as plt
draw_data = [
{
"label": "A",
"whislo": 24, # 下边缘位置
"q1": 25, # 下四分位数(25th百分位数)
"med": 26, # 中位数(50th百分位数)
"q3": 27, # 上四分位数(75th百分位数)
"whishi": 28,
"fliers": [] # 离群值(异常值)
},
{
"label": "B",
"whislo": 25,
"q1": 25,
"med": 26,
"q3": 27,
"whishi": 28
}
]
fig = plt.figure(figsize=(10,6))
ax = fig.add_subplot()
ax.bxp(draw_data, showfliers=False) # showfliers参数用于控制是否显示离群值
ax.set_ylabel("value") # 设置y轴标签
ax.set_xlabel("label") # 设置x轴标签
代码2:
import seaborn as sns
xlabel = ['A','A','A','A','A','A','A','B','B','B','B']
value = [23,12,34,20,21,43,21,28,23,29,29]
ax = sns.boxplot(x=xlabel, y=value) # x参数为标签列表,y参数为对应的值列表
以上是Matlab中绘制箱线图的两种常用方法。通过指定不同的数据和参数,可以绘制出不同类型的箱线图。