Skip to content

Commit

Permalink
feat(wordcloud): add wordcloud_chineseize (#15)
Browse files Browse the repository at this point in the history
* feat(wordcloud): add wordcloud_chineseize
  • Loading branch information
shenxiangzhuang authored Dec 17, 2024
1 parent 22bbc7f commit 4c7f8ab
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@

## [Unreleased]

### Added
- Support chinese display in `wordcloud`


## [0.1.1] - 2024-12-01

### Changed
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ uv add zhplot
import matplotlib.pyplot as plt
```

### 支持的框架
- [x] [matplotlib](https://github.com/matplotlib/matplotlib)
- [x] [wordcloud](https://github.com/amueller/word_cloud)

### 一个简单的例子
<div align="center">
<img src="https://github.com/shenxiangzhuang/zhplot/blob/7569552e07a8b4de7afd8c9df5cbcb154a349e97/docs/images/zhplot_demo.png?raw=true" width="500"/>
Expand All @@ -56,6 +60,7 @@ plt.ylabel('纵坐标')
plt.show()
```


## 相似项目
- [japanize-matplotlib](https://github.com/uehara1414/japanize-matplotlib)
- [chineseize-matplotlib](https://github.com/cndeng/chineseize-matplotlib)
10 changes: 10 additions & 0 deletions tests/test_wordcloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os

import zhplot # noqa


def test_chinese_font_config():
"""Test if wordcloud is configured to use Chinese fonts."""
font_path_env = os.getenv("FONT_PATH")
assert font_path_env is not None
assert "NotoSansSC-Regular" in font_path_env
2 changes: 2 additions & 0 deletions zhplot/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from .matplotlib import matplotlib_chineseize
from .wordcloud import wordcloud_chineseize

__all__ = [
"matplotlib_chineseize",
"wordcloud_chineseize",
]
10 changes: 10 additions & 0 deletions zhplot/wordcloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import os
from pathlib import Path


def wordcloud_chineseize():
font_ttf: str = "NotoSansSC-Regular.ttf"
os.environ["FONT_PATH"] = f"{Path(__file__).parent}/fonts/{font_ttf}"


wordcloud_chineseize()

0 comments on commit 4c7f8ab

Please sign in to comment.