温馨提示×

Matplotlib中怎么设置图例的字体大小

小亿
90
2024-05-11 18:52:50
栏目: 编程语言

要设置Matplotlib图例的字体大小,可以使用fontsize参数来指定字体大小。以下是一个示例代码:

import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [10, 20, 15, 25, 30]

plt.plot(x, y, label='data')
plt.legend(fontsize='large')  # 设置图例的字体大小为large
plt.show()

在上面的示例中,plt.legend(fontsize='large')语句指定了图例的字体大小为large。您可以根据需要将fontsize参数设置为不同的值,如small, medium, large, x-large等。您也可以直接指定字体的大小,比如plt.legend(fontsize=12)

0