Skip to content

Commit 2aabe57

Browse files
committed
feat(plot): 添加 matplotlib 字体配置模块
docs: 更新文档内容并添加 Anaconda3 文档 build: 更新项目版本和 Python 要求
1 parent 2e7ef62 commit 2aabe57

File tree

7 files changed

+81
-3
lines changed

7 files changed

+81
-3
lines changed

doc/InsightHub/Anaconda3/index.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Anaconda3
2+
3+
参考 [Anaconda3 文档](https://www.anaconda.com/docs/main)
4+
5+
Anaconda® Distribution 是 Python/R 的数据科学发行版,包含:
6+
7+
* [conda](https://docs.conda.io/en/latest): 用于命令行界面的包和环境管理器。
8+
* [Anaconda Navigator](/tools/anaconda-navigator/main): 基于 conda 构建的桌面应用程序,可从您管理的环境中启动其他开发应用程序。
9+
* [超过 300 个自动安装的包](/getting-started/anaconda/release-notes),这些包开箱即用,协同工作良好。
10+
* 访问 [Anaconda 公共仓库](https://repo.anaconda.com/pkgs/),其中包含 8000 个开源数据科学和机器学习包。Anaconda 包仓库的 [RSS 源](http://repo.anaconda.com/pkgs/rss.xml) 每次有新包添加时都会更新。
11+
* [Anaconda mcp](https://docs.anaconda.com/mcp/): 在 Anaconda 知识库中搜索,以查找相关信息、代码示例、API 参考和指南。当您需要回答有关 Anaconda 的问题、查找特定文档、了解功能的工作原理或定位实现细节时,请使用此工具。搜索结果将返回包含标题和直接链接到文档页面的上下文内容。

doc/InsightHub/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
# 智汇源
22

3+
收录一些有趣的项目,用于启发和学习。
4+
35
```{toctree}
46
pygallery <https://daobook.github.io/pygallery>
57
maple-mono/index
68
Matplotlib/index
9+
Anaconda3/index
710
Trae/index
811
iFlow/index
912
zeromq/index

doc/notebook/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 📒笔记本
22

3-
借助 [obsidian](https://obsidian.md/)[简悦](http://simpread.pro/) 做笔记
3+
借助 [obsidian](https://obsidian.md/)[简悦](http://simpread.pro/) 等工具做笔记
44

55
```{toctree}
66
Clippings/index

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
[project]
22
name = "taolib"
3-
version = "0.0.10"
3+
version = "0.1.0"
44
description = "道可道,非恒道"
55
authors = [
66
{name = "xinetzone", email = "[email protected]"},
77
]
8-
requires-python = ">=3.12"
8+
requires-python = ">=3.10"
99
readme = "README.md"
1010
license = {file = "LICENSE"}
1111
maintainers = [

src/taolib/plot/__init__.py

Whitespace-only changes.

src/taolib/plot/configs/__init__.py

Whitespace-only changes.
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
"""
2+
matplotlib 字体配置模块
3+
4+
此模块提供了配置 matplotlib 中文字体显示的功能,自动加载指定目录下的字体文件
5+
并设置 matplotlib 使用中文字体,确保图表中的中文能正确显示。
6+
"""
7+
import matplotlib.pyplot as plt
8+
from matplotlib import font_manager
9+
from pathlib import Path
10+
import logging
11+
logger = logging.getLogger(__name__) # 创建日志记录器
12+
13+
def configure_matplotlib_fonts(font_directory: str = None, target_fonts: list[str] = ['Maple Mono NF CN']) -> bool:
14+
"""
15+
配置 matplotlib 的字体设置
16+
17+
参数:
18+
font_directory: 字体文件所在目录路径,如果为 None 则使用默认路径
19+
target_fonts: 要设置的目标字体名称
20+
21+
返回:
22+
bool: 配置是否成功
23+
"""
24+
try:
25+
# 如果未提供字体目录,使用默认目录
26+
if font_directory is None:
27+
root_dir = Path(__file__).resolve().parents[0]
28+
font_directory = str(root_dir / "fonts")
29+
30+
# 确保字体目录存在
31+
font_dir_path = Path(font_directory)
32+
if not font_dir_path.exists():
33+
logger.warning(f"字体目录不存在: {font_directory}")
34+
return False
35+
36+
# 查找字体文件
37+
font_files = font_manager.findSystemFonts(fontpaths=[font_directory])
38+
39+
if not font_files:
40+
logger.warning(f"在 {font_directory} 中未找到任何字体文件")
41+
return False
42+
43+
# 加载字体文件
44+
for font_file in font_files:
45+
try:
46+
font_manager.fontManager.addfont(font_file)
47+
logger.debug(f"成功加载字体: {font_file}")
48+
except Exception as e:
49+
logger.error(f"加载字体失败 {font_file}: {e}")
50+
51+
# 设置 matplotlib 字体
52+
plt.rcParams["font.family"] = target_fonts
53+
logger.debug(f"已成功配置 matplotlib 使用字体: {target_fonts}")
54+
55+
return True
56+
57+
except Exception as e:
58+
logger.error(f"配置 matplotlib 字体时发生错误: {e}")
59+
return False
60+
61+
62+
# 如果直接运行此脚本,则执行字体配置
63+
if __name__ == "__main__":
64+
configure_matplotlib_fonts()

0 commit comments

Comments
 (0)