案例

案例一

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# [email protected]柱状图
import matplotlib.pyplot as plt
import numpy as np
# 解决中文显示问题
plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.family'] = ['SimSun']
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 模拟数据,你需要替换这些数据为你实际的模型结果
models = ['FR', 'YOLOX', '文献1', '文献2', 'Yolov8-3']
r2_scores = [
0.510,
0.540,
0.495,
0.505,
0.570
]
# 定义颜色
colors = ['r', 'Orange', "Brown", "Teal", "BLACK"]
# 设置图形大小
fig, ax1 = plt.subplots(figsize=(4, 4))
# 绘制 R2 图
# 设置柱状图的宽度
bar_width = 0.58
bars_r2 = ax1.bar(models, r2_scores, color=colors, width=bar_width)
ax1.set_ylabel('[email protected]:0.95', fontsize=12)
# 显示具体数值
for bar in bars_r2:
    yval = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2, yval, round(yval, 3), ha='center', va='bottom', fontsize=12)
# 去除边框线
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['left'].set_visible(True)
ax1.spines['bottom'].set_visible(True)
# 调整布局,去除周围空白
plt.subplots_adjust(left=0.145, right=0.98, bottom=0.06, top=0.98, wspace=0.4, hspace=0.8)
# 调整 x 轴和 y 轴刻度的字体大小
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
plt.savefig('[email protected]', dpi=400)

输出结果

案例二

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# [email protected]柱状图
import matplotlib.pyplot as plt
import numpy as np
# 解决中文显示问题
plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.family'] = ['SimSun']
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
# 模拟数据,你需要替换这些数据为你实际的模型结果
models = ['FR', 'YOLOX', '文献1', '文献2', 'Yolov8-3']
r2_scores = [
0.840,
0.860,
0.825,
0.835,
0.880
]
# 定义颜色
colors = ['r', 'Orange', "Brown", "Teal", "BLACK"]
# 设置图形大小
fig, ax1 = plt.subplots(figsize=(4, 4))
# 绘制 R2 图
# 设置柱状图的宽度
bar_width = 0.58
bars_r2 = ax1.bar(models, r2_scores, color=colors, width=bar_width)
ax1.set_ylabel('[email protected]/%', fontsize=12)
# 显示具体数值
for bar in bars_r2:
    yval = bar.get_height()
    ax1.text(bar.get_x() + bar.get_width()/2, yval, round(yval, 3), ha='center', va='bottom', fontsize=12)
# 去除边框线
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['left'].set_visible(True)
ax1.spines['bottom'].set_visible(True)
# 调整布局,去除周围空白
plt.subplots_adjust(left=0.145, right=0.98, bottom=0.06, top=0.98, wspace=0.4, hspace=0.8)
# 调整 x 轴和 y 轴刻度的字体大小
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)
plt.savefig('[email protected]', dpi=400)

输出结果

案例三

源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# P柱状图
import matplotlib.pyplot as plt
import numpy as np

# 解决中文显示问题
plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.family'] = ['SimSun']
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False


# 模拟数据,你需要替换这些数据为你实际的模型结果
models = ['FR', 'YOLOX', '文献1', '文献2', 'Yolov8-3']

r2_scores = [
0.89,
0.91,
0.87,
0.88,
0.93

]

# 定义颜色
colors = ['r', 'Orange', "Brown", "Teal", "BLACK"]

# 设置图形大小
fig, ax1 = plt.subplots(figsize=(4, 4))
# 绘制 R2 图
# 设置柱状图的宽度
bar_width = 0.58

bars_r2 = ax1.bar(models, r2_scores, color=colors, width=bar_width)
ax1.set_ylabel('P/%', fontsize=12)
# 显示具体数值
for bar in bars_r2:
yval = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2, yval, round(yval, 3), ha='center', va='bottom', fontsize=12)

# 去除边框线
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['left'].set_visible(True)
ax1.spines['bottom'].set_visible(True)

# 调整布局,去除周围空白
plt.subplots_adjust(left=0.145, right=0.98, bottom=0.06, top=0.98, wspace=0.4, hspace=0.8)

# 调整 x 轴和 y 轴刻度的字体大小
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)

plt.savefig('P.png', dpi=400)

输出结果

案例四

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import matplotlib.pyplot as plt
import numpy as np

# 解决中文显示问题
plt.rcParams['font.family'] = 'Times New Roman'
plt.rcParams['font.family'] = ['SimSun']
plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False


# 模拟数据,你需要替换这些数据为你实际的模型结果
models = ['FR', 'YOLOX', '文献1', '文献2', 'Yolov8-3']

r2_scores = [
0.76,
0.79,
0.75,
0.77,
0.83


]

# 定义颜色
colors = ['r', 'Orange', "Brown", "Teal", "BLACK"]

# 设置图形大小
fig, ax1 = plt.subplots(figsize=(4, 4))
# 绘制 R2 图
# 设置柱状图的宽度
bar_width = 0.58

bars_r2 = ax1.bar(models, r2_scores, color=colors, width=bar_width)
ax1.set_ylabel('R/%', fontsize=12)
# 显示具体数值
for bar in bars_r2:
yval = bar.get_height()
ax1.text(bar.get_x() + bar.get_width()/2, yval, round(yval, 3), ha='center', va='bottom', fontsize=12)

# 去除边框线
ax1.spines['top'].set_visible(False)
ax1.spines['right'].set_visible(False)
ax1.spines['left'].set_visible(True)
ax1.spines['bottom'].set_visible(True)

# 调整布局,去除周围空白
plt.subplots_adjust(left=0.145, right=0.98, bottom=0.06, top=0.98, wspace=0.4, hspace=0.8)

# 调整 x 轴和 y 轴刻度的字体大小
plt.xticks(fontsize=12)
plt.yticks(fontsize=12)

plt.savefig('R.png', dpi=400)

输出结果