问题解决方案

1. Python 利用Matplotlib绘图时,无法显示中文字体的解决方案

根据网上的解决办法,先进行代码的设置:

python 复制代码
from matplotlib.font_manager import FontProperties

font = FontProperties(fname=" /SIMHEI.TTF")  # 替换为实际的字体文件路径
plt.rcParams['font.sans-serif'] = [font.get_name()]
plt.rcParams['axes.unicode_minus'] = False

如果设置的字体没有,则需要安装字体。

字体安装完成之后,还是报错,找不到字体,则需要:

python 复制代码
import matplotlib
print(matplotlib.matplotlib_fname())

运行代码,查找库的位置

虚拟环境当中可以:pip show 包名

找到对应的位置,进入ttf 目录:

/home/book/.local/lib/python3.5/site-packages/matplotlib/mpl-data/matplotlibrc/fonts/ttf

将安装的对应字体,复制一份到这目录下面

然后测试,如果还是不行,则清除缓存:

~/.cache/matplotlib/fontlist-v300.json(将文件删除)

删除之后重新启动对应的代码,即可

2. 虚拟环境安装(conda install)遇到:

Collecting package metadata (current_repodata.json): failed CondaSSLError: Encountered an SSL error. Most likely a certificate verification issue. Exception: HTTPSConnectionPool(host='repo.anaconda.com', port=443): Max retries exceeded with url: /pkgs/main/linux-64/current_repodata.json (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:997)')))

先运行conda config --show-sources查找.condarc文件文件,然后把文件的内容替换为以下内容即可:

python 复制代码
channels:
  - defaults
show_channel_urls: true
channel_alias: http://mirrors.tuna.tsinghua.edu.cn/anaconda
default_channels:
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/free
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/pro
  - http://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
  conda-forge: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  msys2: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  bioconda: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  menpo: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  pytorch: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
  simpleitk: http://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
相关推荐
敲代码的瓦龙19 小时前
Java?泛型!!!
windows·python·microsoft
xiaotao13119 小时前
01-编程基础与数学基石: 常用内置库
开发语言·人工智能·python
DaqunChen19 小时前
PHP怎么实现单例模式_PHP常用设计模式之单例模式【方法】
jvm·数据库·python
2301_8035389519 小时前
Matplotlib 动画中多子图更新失效的解决方案
jvm·数据库·python
ZC跨境爬虫19 小时前
纯requests+Redis实现分布式爬虫(可视化4终端,模拟4台电脑联合爬取)
redis·分布式·爬虫·python
Irene19911 天前
Python 卸载与安装(以卸载3.13.3,装3.13.13为例)
python
予早1 天前
使用 pyrasite-ng 和 guppy3 做内存分析
python·内存分析
hef2881 天前
如何生成特定SQL的AWR报告_@awrsqrpt.sql深度剖析单条语句性能
jvm·数据库·python
Jinkxs1 天前
从语法纠错到项目重构:Python+Copilot 的全流程开发效率提升指南
python·重构·copilot
技术专家1 天前
Stable Diffusion系列的详细讨论 / Detailed Discussion of the Stable Diffusion Series
人工智能·python·算法·推荐算法·1024程序员节