Python drawing settings Arial and New Roman Times New Roman

Python drawing settings Arial and New Roman Times New Roman

I believe that many friends who use Python to draw pictures will be confused. Every time the picture drawn is in bold, and pasted into Word, it does not match other text, but I am too lazy to change it. The main reason is that I have not found a good one. It is an effective method, but today I accidentally learned a method and found it very useful, so I will share it with you

import matplotlib.pyplot as plt
from matplotlib import rcParams

config = {
    
    
            "font.family": 'serif',
            "font.size": 12,# 相当于小四大小
            "mathtext.fontset": 'stix',#matplotlib渲染数学字体时使用的字体,和Times New Roman差别不大
            "font.serif": ['SimSun'],#宋体
            'axes.unicode_minus': False # 处理负号,即-号
         }
rcParams.update(config)

Add the above code before drawing the picture and it will be OK

x_data = ['2013','2014','2015','2016','2017','2018','2019','2020']  
y_data = [63000,71000,84000,90500,107000,120000,134000,145000] 
plt.figure(figsize=(9,8))
plt.plot(x_data, y_data, "r", marker='*', ms=10, label="a")
plt.xlabel("我是x轴", fontsize = 20)
plt.ylabel("我是y轴", fontsize = 20)
plt.title('我是标题', fontsize = 20)
plt.tick_params(labelsize=13)
plt.savefig('折线图.png', dpi=500, bbox_inches='tight') # 解决图片不清晰,不完整的问题
plt.show()

The following is the effect, I am very happy, I hope it can help you who are confused.

insert image description here

Guess you like

Origin blog.csdn.net/weixin_43697614/article/details/124219278