一、纯英文图像可视化
- 直接Times new roman格式,在代码最前面全局设置即可,需要给出字体的路径
font_path = '/home/jie/Downloads/times.ttf'
prop = font_manager.FontProperties(fname=font_path)
plt.rcParams['font.family'] = prop.get_name()
labels = ['C1', 'C2', 'C3', 'C4', 'C5']
men_means = [20, 35, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
men_std = [2, 3, 4, 1, 2]
women_std = [3, 5, 2, 3, 3]
width = 0.35 # the width of the bars: can also be len(x) sequence
# ========= exhibit the bar image ===========
x = np.arange(len(labels)) # the label locations
fig = plt.figure(figsize=(8, 5))
ax = fig.add_subplot(1, 1, 1)
plt.bar(x - width/2, men_means, width, label='men')
plt.bar(x + width/2, women_means, width, label='women')
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_xlabel('Class')
ax.set_ylabel('Number')
# ax.set_title('Three types rock classification result')
ax.set(xticks=x, xticklabels=labels)
ax.set_xlabel(xlabel='men', fontsize=15)
ax.set_ylabel(ylabel='Number', fontsize=15)
ax.legend(loc="upper right", fontsize=15)
plt.yticks(fontsize=15)
plt.xticks(fontsize=15)
# 添加数据标签
for a, b in zip(x-width/2, men_means):
plt.text(a, b, '%d' % (b) , ha='center', va='bottom', fontsize=10)
for a, b in zip(x + width/2, women_means):
plt.text(a, b, '%d' % (b) , ha='center', va='bottom', fontsize=10)
fig.tight_layout()
plt.show()
二、中英文互搭模式
- 有时候需要显示中文的图名、坐标轴名,然后对刻度值或者其他的数字依旧需要Times new roman格式。切忌在中文之前一定记得加u,然后一句话中同时存在中文和英文则需要有转义符
ax.set_title("考试成绩\n$\mathrm{Scores\ higher\ than\ 90}$")
,详情见下图图名。
config = {
"font.family": "serif", # 使用衬线体
"font.serif": ["SimHei"], # 全局默认使用衬线宋体
"font.size": 14, # 五号,10.5磅
"axes.unicode_minus": False,
"mathtext.fontset": "stix", # 设置 LaTeX 字体,stix 近似于 Times 字体
}
plt.rcParams.update(config)
labels = ['C1', 'C2', 'C3', 'C4', 'C5']
men_means = [20, 35, 30, 35, 27]
women_means = [25, 32, 34, 20, 25]
men_std = [2, 3, 4, 1, 2]
women_std = [3, 5, 2, 3, 3]
width = 0.35 # the width of the bars: can also be len(x) sequence
# ========= exhibit the bar image ===========
x = np.arange(len(labels)) # the label locations
fig = plt.figure(figsize=(8, 5))
ax = fig.add_subplot(1, 1, 1)
plt.bar(x - width/2, men_means, width, label=u'男生')
plt.bar(x + width/2, women_means, width, label=u'女生')
# #设置图例并且设置图例的字体及大小
font1 = {'family' : 'Times New Roman',
'weight' : 'normal',
'size' : 15,
}
# plt.legend(prop=font1)
# 坐标系标签使用西文字体
ticklabels_style = {
"fontname": "Times New Roman",
"fontsize": 12, # 小五号,9磅
}
#设置坐标刻度值的大小以及刻度值的字体
plt.yticks(**ticklabels_style)
plt.xticks(**ticklabels_style)
# Add some text for labels, title and custom x-axis tick labels, etc.
ax.set_xlabel(u'班级')
ax.set_ylabel(u'数量/(人)')
# ax.set_title('Three types rock classification result')
ax.set(xticks=x, xticklabels=labels)
ax.set_xlabel(xlabel=u'班级', fontsize=15)
ax.set_ylabel(ylabel=u'数量/(人)', fontsize=15)
ax.legend(loc="upper right", fontsize=15)
ax.set_title("考试成绩\n$\mathrm{Scores\ higher\ than\ 90}$")
# 添加数据标签
for a, b in zip(x-width/2, men_means):
plt.text(a, b, '%d' % (b) , ha='center', va='bottom', fontsize=10, fontproperties = font1)
for a, b in zip(x + width/2, women_means):
plt.text(a, b, '%d' % (b) , ha='center', va='bottom', fontsize=10, fontproperties = font1)
fig.tight_layout()
# plt.show()
plt.savefig(os.path.join('./柱状图.jpg'), dpi=1280, bbox_inches='tight')
plt.close()
另:本团队由数名top高校博硕士组成,目前正在做的项目有基于深度学习技术、三维激光点云、SLAM等在安防、自动驾驶领域的感知算法研究和落地以及工业生产智能化改造。
有项目意向的可交流沟通
QQ:812108841