selfteaching / selfteaching/selfteaching-python-camp
Day13 解决matplotlib画图中文显示问题--windows版(永久)
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 151
- Forks
- 875
- PR merge metrics
- No merged PRs in 30d
Description
对于第13天的作业,问的最多的一个问题就是matplotlib中文显示问题,看到之前有人已经做过相关的回答。此处说一下,我解决的办法,此办法可以永久解决显示,不需要每次画图都导入一遍字体。
步骤
1.先下载一款字体,为了方便大家统一操作,此处给大家准备了一款,直接使用即可。
链接:https://pan.baidu.com/s/1gkQlIHulFVDYGdgiT8mbow
提取码:oh70
2.在你的jupyter中写入如下代码,然后运行:
import matplotlib
matplotlib.matplotlib_fname()
输出的结果是一个路径,保存好次路径,下面经常用到。
示例:'C:\D(english path)\Anaconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc'
3.上面示例中的路径最后指向的是一个文件,大家打开即可。看的两个反斜线,第一个是转义字符,第二个是目录的符号,比如上面示例,代表的就是c盘下面的D(english path)目录下面...巴拉巴拉一大堆。
4.打开后,在字体的那一块代码前面输入以下代码:(如果看不懂英文,那就直接下拉到195行)
font.family : sans-serif
font.sans-serif : simhei
axes.unicode_minus : False
写完后保存。
5.之前让你保存的路径还在呢吧?往上一级目录走,在mpl-data目录下找目录fonts下的ttf,然后把你下载的字体,扔进去。
6.别急,还有一步操作。那就是清除缓存,打开你的家目录,找隐藏文件夹.matplotlib,然后删掉,尽管删,反正不是我电脑,哈哈哈,开个玩笑。
你有可能找不到这个目录,我教你:
打开C盘,在用户文件夹中找到你的电脑用户名文件夹,然后点进去。每个人的电脑名字不一样,大家自己找找吧。里面就两三个文件夹,应该不会找错,找到后点击去,里面就有隐藏文件夹.matplotlib,如果你的电脑没有显示这个目录,第一个原因就是它隐藏了,你百度一下很简单,第二个原因就是你没用过matplotlib这个模块。公用文件夹就是你电脑上其他用户也可以访问的文件。
7.最后一步就是重启你的jupyter,然后再试试之前的代码吧
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Review the issue's Windows and Jupyter steps for matplotlib Chinese-font configuration, including the referenced matplotlibrc path, fonts/ttf directory, and .matplotlib cache. Verify the instructions with the provided code and confirm that the documented process still works; done means the guidance is accurate and usable.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter, matplotlib, python
- Domain
- data-visualization, documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100