常规绘图流程
import numpy as np import matplotlib import matplotlib.pyplot as plt # 关于matplotlib绘图Times New Roman字体问题 # https://blog.csdn.net/Limonor/article/details/106392436 # 解决字体不一致问题, 设置全局字体为Times New Roman plt.rc('font', family='Times New Roman') # 解决Times New Roman字体加粗问题 del matplotlib.font_manager.weight_dict['roman'] matplotlib.font_manager._rebuild() # Data x = np.random.rand(10, 1) y = np.random.rand(10, 1) # 定义字体 font1 = {'family': 'Times New Roman', 'weight': 'normal', 'size': 10} font2 = {'family': 'Times New Roman', 'style': 'italic', 'weight': 'normal', 'size': 12} # 创建figure fig, ax = plt.subplots(figsize=[10*0.3937008, 4*0.3937008], dpi=600) # 英寸改为厘米 # fig, ax = plt.subplots(figsize=[7.5*0.3937008, 4*0.3937008], dpi=600) # fig, ax = plt.subplots(figsize=[10*0.3937008, 4*0.3937008], dpi=600) #fig, ax = plt.subplots(figsize=[15*0.3937008, 7*0.3937008], dpi=600) #fig, = plt.figure(figsize=[15*0.3937008, 7*0.3937008], dpi=600) ax.plot(x, y, color='r', linestyle='-', linewidth=1, marker='o', markersize=2, label='this is a ') #plt.tight_layout(pad=3) plt.gca().set_xlim(0, 1) plt.gca().set_ylim(0, 1) plt.tick_params(labelsize=10) plt.xlabel('x', font2) plt.ylabel('y', font2) plt.title("This is title: {}".format(111), font1) plt.legend(loc=1, prop=font1, frameon=False) plt.savefig('demo.png', dpi=1000, bbox_inches='tight') #plt.tight_layout() #plt.show() if __name__ == '__main__': pass
全局参数设置
plt.rcParams['Property'] = value plt.rc('Property': value)
plt.rcParams['savefig.dpi'] = 600 #保存图像分辨率 plt.rcParams['figure.dpi'] = 600 #plt.show()显示分辨率
plt.rcParams['figure.figsize'] = (10, 4.0) # 图像显示大小