用默认的字体时,'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')
结果为