关于人工智能:matplotlib的安装和使用教程中文字体及语言参数设置

5次阅读

共计 1245 个字符,预计需要花费 4 分钟才能阅读完成。

matplotlib 是一个罕用的数据可视化库,广泛应用于科学研究、工程设计、金融剖析等畛域。因为其弱小的性能和易用性,matplotlib 曾经成为了宽广科研工作者和数据分析师的必备工具之一。本文将重点介绍 matplotlib 的装置和容许中文及几种字体的办法。

一、matplotlib 的装置

matplotlib 能够通过多种路径进行装置,其中最简略的办法是通过命令行进行装置。在命令行中,能够应用以下命令进行装置:

pip install matplotlib

这个命令将在 pip 官方网站上下载并装置 matplotlib。装置实现后,能够在命令行中输出 matplotlib 来启动 matplotlib 编辑器。

如果想要装置在线版本的 matplotlib,能够应用以下命令:

pip install matplotlib-online

这个命令将在 matplotlib 官方网站上下载并装置 matplotlib-online。装置实现后,能够在命令行中输出 matplotlib-online 来启动 matplotlib 编辑器。

二、matplotlib 的容许中文及几种字体

为了不便中国用户应用 matplotlib,matplotlib 曾经反对中文字体。在 matplotlib 的装置过程中,能够通过批改装置门路或者在 matplotlib 配置文件中设置语言参数来实现。上面将别离介绍如何设置 matplotlib 的中文字体和语言参数。

1、设置 matplotlib 的中文字体

在 matplotlib 的装置门路下,找到 matplotlib 的配置文件(matplotlib/config.py)。关上配置文件,能够看到以下字段:

MA_FONTSIZE = 14

将 MA_FONTSIZE 批改为你喜爱的大小即可。例如,将 MA_FONTSIZE 批改为 20,将会把字体大小设置为 20。

2、设置 matplotlib 的语言参数

如果你在 matplotlib 的配置文件中曾经设置了 MA_FONTSIZE,那么你能够通过批改 matplotlib 的装置门路或者在 matplotlib 配置文件中设置语言参数来实现中文字体的显示。例如,将 matplotlib 的装置门路批改为以下门路:

/home/user/matplotlib/lib/python3.6/site-packages/matplotlib/mpl-data/chinese.ttf

或者在 matplotlib 的配置文件中设置以下语言参数:

matplotlib.rcParams['font.family'] = 'SimHei'
matplotlib.rcParams['font.sans-serif'] = ['SimHei']
matplotlib.rcParams['font.serif'] = ['SimHei']

这样设置后,matplotlib 将会应用 SimHei 字体作为默认字体,并且反对中文字体。

通过以上两种办法,你能够不便地在 matplotlib 中应用中文及几种字体。

本文由 mdnice 多平台公布

正文完
 0