背景:
win10, anaconda 4.8.3, python 3.8.3,在matplotlib.pyplot画图时,发现一些字体的属性不起作用
办法
检查windows系统字体文件夹下,各字体文件的style show/hide信息。有些字体的 font style 只有Regular , 那么即使在程序中更改了fontdict(style='italic"), 也不会有斜体效果,但是程序也不报错。图片见下。例子程序见图片下方。
import matplotlib
.pyplot
as plt
import numpy
as np
plt
.rcParams
['axes.unicode_minus']=False
x
=np
.linspace
(0.5, 3.5, 100)
y
=np
.sin
(x
)
fig
=plt
.figure
(figsize
=(8,8))
ax
=fig
.add_subplot
(111)
face_edge_color
='r'
box
=dict(facecolor
=face_edge_color
, pad
=2, alpha
=0.4, edgecolor
=face_edge_color
,)
ax
.plot
(x
,y
, c
='b', ls
='--', lw
=2)
title
="y=sin(x)"
xaxis_label
="$x\_axis$"
yaxis_label
="$y\_axis$"
ax
.set_xlabel
(xaxis_label
, fontsize
=18, bbox
=box
)
ax
.set_ylabel
(yaxis_label
, fontsize
=18, bbox
=box
)
ax
.set_title
(title
, va
="bottom",
fontdict
=dict(fontsize
=16,
color
='r',
family
='Times New Roman',
weight
='light',
style
='italic',
),
)
ax
.yaxis
.set_label_coords
(-0.08, 0.5)
ax
.xaxis
.set_label_coords
(1.0, -0.05)
ax
.grid
(ls
='-.', lw
=1, color
='gray', alpha
=0.5)
plt
.show
()