新闻资讯

质量为本、客户为根、勇于拼搏、务实创新

< 返回新闻资讯列表

Matplotlib中如何设置图例的字体大小,matplotlib.figure

发布时间:2024-05-11 18:52:50

Matplotlib中如何设置图例的字体大小

要设置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)