matplotlib科研绘图---TimesNewRoman字体设置matplotlib科研绘图—Times New Roman字体设置
⼀、
plt.figure(figsize=[15,8])
plt.scatter(X, Y, label ='RealValue')
plt.plot(X, func(X, a, b),'red', label ='CurveLine')
plt.title(station, fontdict={'family':'Times New Roman','size':16})
plt.ylabel('Clocks($\mu S$)', fontdict={'family':'Times New Roman','size':16})
plt.xlabel('Time', fontdict={'family':'Times New Roman','size':16})
plt.legend(prop={'family':'Times New Roman','size':16})
matplotlib中subplotplt.savefig('./stationClocks/'+ station +'.ps', dpi =200)
plt.show()
⼆、
解决字体不⼀致的⽅法
将全局字体改为Times New Roman
import matplotlib.pyplot as plt
<('font',family='Times New Roman')
解决Times New Roman加粗的问题
del matplotlib.font_manager.weight_dict['roman']
matplotlib.font_manager._rebuild()
三、⼀些参数
⽤默认的字体时,'weight’的变化是可以改变字体粗细的,以下是代码
import matplotlib.pyplot as plt
styles=['normal','italic','oblique']
weights=['ultralight','light','normal','regular','book','medium','roman','semibold','demibold','demi','bold','heavy','extra bold','black'] plt.figure(figsize=(15,3))
for i in range(len(styles)):
for j in range(len(weights)):
font={'style':styles[i],'weight':weights[j]}
plt.subplot(len(styles),len(weights),i*len(weights)+j+1)
plt.plot([1,2,3,4],[1,4,9,16],'b', label='VGG-16')
plt.legend(loc='upper right', prop=font)
plt.savefig('style.png')
⼀旦把字体设定为’Times New Roman’,'weight’就没办法调节说明框中字体的粗细
import matplotlib.pyplot as plt
styles=['normal','italic','oblique']
weights=['ultralight','light','normal','regular','book','medium','roman','semibold','demibold','demi','bold','heavy','extra bold','black'] plt.figure(figsize=(15,3))
for i in range(len(styles)):
for j in range(len(weights)):
font={'family':'Times New Roman','style':styles[i],'weight':weights[j]}
plt.subplot(len(styles),len(weights),i*len(weights)+j+1)
plt.plot([1,2,3,4],[1,4,9,16],'b', label='VGG-16')
plt.legend(loc='upper right', prop=font)
plt.savefig('style.png')
四、
# coding=utf-8
import numpy as np
import matplotlib.pyplot as plt
x = np.array([1,2,3,4,5,6])
VGG_supervised = np.array([2.9749694,3.9357018,4.7440844,6.482254,8.720203,13.687582])
VGG_unsupervised = np.array([2.1044724,2.9757383,3.7754183,5.686206,8.367847,14.144531])
ourNetwork = np.array([2.0205495,2.6509762,3.1876223,4.380781,6.004548,9.9298])
# label在图⽰(legend)中显⽰。若为数学公式,则最好在字符串前后添加"$"符号
# color:b:blue、g:green、r:red、c:cyan、m:magenta、y:yellow、k:black、w:white、、、
# 线型:- -- -. : ,
# marker:. , o v < * + 1
plt.figure(figsize=(10,5))
ax = a()
ax.spines['top'].set_visible(False)# 去掉上边框
ax.spines['right'].set_visible(False)# 去掉右边框
plt.plot(x, VGG_supervised, marker='o', color="blue", label="VGG-style Supervised Network", linewidth=1.5)
plt.plot(x, VGG_unsupervised, marker='o', color="green", label="VGG-style Unsupervised Network", linewidth=1.5) plt.plot(x, ourNetwork, marker='o', color="red", label="ShuffleNet-style Network", linewidth=1.5)
group_labels =['Top 0-5%','Top 5-10%','Top 10-20%','Top 20-50%','Top 50-70%',' Top 70-100%']# x轴刻度的标识icks(x, group_labels, fontsize=12, fontweight='bold')# 默认字体⼤⼩为10
# plt.title("example", fontsize=12, fontweight='bold') # 默认字体⼤⼩为12
plt.xlabel("Performance Percentile", fontsize=13, fontweight='bold')
plt.ylabel("4pt-Homography RMSE", fontsize=13, fontweight='bold')
plt.xlim(0.9,6.1)# 设置x轴的范围
plt.ylim(1.5,16)
# plt.legend() #显⽰各曲线的图例
plt.legend(loc=0, numpoints=1)
leg = a().get_legend()
ltext = _texts()
plt.setp(ltext, fontsize=12, fontweight='bold')# 设置图例字体的⼤⼩和粗细
plt.savefig('./filename.svg',format='svg')# 建议保存为svg格式,再⽤inkscape转为⽮量图emf后插⼊word中
plt.show()
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论