问题解决方案

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
相关推荐
XZ-07000120 分钟前
week4-1-figure画布
python
步行cgn1 小时前
Spring 注入 Map 集合详解
数据库·python·spring
今儿敲了吗1 小时前
03停用词过滤
笔记·python
李可以量化2 小时前
Tornado 部署公域网络安全与防护(上)
python
风跟我说过她2 小时前
SQL 一键转经典 Chen 风格 ER 图:开源 CLI + 在线工具 + Agent Skill
数据库·python·sql·开源·开源软件
Ulyanov2 小时前
AudioVision Pro:基于 PySide6 + sounddevice 的实时音频可视化播放器设计
python·算法·音视频
ID34610744202 小时前
【课程设计】基于Spring Boot+Vue的校园共享无人机服务系统设计与实现-计算机毕设 附源码44219
javascript·vue.js·spring boot·python·node.js·php·课程设计
星空2 小时前
pycharm复习
ide·python·pycharm
Maiko Star2 小时前
Python 包与项目管理工具——uv
python·uv
weixin199701080163 小时前
[特殊字符]《京东POP二手品类对接:B2C订单模型 vs 二手C2C属性的字段转换难题》(附Python源码)
前端·python·算法