# cmplstyle
A Python package providing matplotlib style for scientific plotting with traditional Chinese color palette.
## Installation
You can install the package using pip:
```bash
pip install cmplstyle
```
## Features
- A collection of 365 traditional Chinese colors.
- Optmised matplotlib style for scientific plotting.
- Small handy functions for helping scientific plotting.
## Traditional Chinese Colors (TCC)
Our color collection is sourced from the reference [《中国传统色:国民版色卡》](https://www.douban.com/doubanapp/dispatch/book/35951952?dt_dapp=1) by 郭浩, featuring hues widely used in traditional Chinese art and design. See [here](https://jinyiliu.github.io/2025/08/13/cmplstyle/TCC_ncols_5.pdf) for a complete color reference.
The color names are in Chinese and their HEX color values are stored in the `cmplstyle.TCC` dictionary. Once the package is imported, the colors can be accessed easily by their names. For example,
```python
import cmplstyle
import seaborn
seaborn.palplot(["群青", "西子", "胭脂", "桂黄", "苍苍", "青骊", "官绿", "米汤娇", "沧浪", "梅子青", "石榴裙"])
```
will plot a color palette with the specified colors in the list:

For readers unfamiliar with Chinese characters, the colors can also be accessed by the numbered indices (`TCC_1` through `TCC_365`). See [here](https://jinyiliu.github.io/2025/08/13/cmplstyle/TCC_indexed_ncols_5.pdf) for a complete indexed color reference.
The package provides conversions between Chinese color names and their `TCC_` indexed names: use `cmplstyle.color_index_to_name` to retrieve the Chinese name for a given `TCC_` index, and `cmplstyle.index_name_to_color` to find the corresponding `TCC_` index for a Chinese color name.
## Built-in Matplotlib style
The package includes a built-in Matplotlib style. Activate it with:
```python
import cmplstyle
cmplstyle.use_builtin_mplstyle()
```
### Example: Linear regression plot

<details>
<summary>View Plotting Code</summary>
```python
import numpy as np
import matplotlib.pyplot as plt
import cmplstyle
from cmplstyle import onecol_wth, cm2inch
cmplstyle.use_builtin_mplstyle()
np.random.seed(20)
F = lambda x: 2.0 * x + 3.0
X = np.linspace(0, 10, 100)
N = 15 # sample size
Y_NOISE_STD_MIN = 5.0
Y_NOISE_STD_MAX = 15.0
X_sample = np.random.normal(loc=5, scale=2, size=N)
Y_sample = F(X_sample)
NOISE_STD = np.random.uniform(Y_NOISE_STD_MIN, Y_NOISE_STD_MAX, size=N)
Y_sample += np.random.normal(size=N) * NOISE_STD
# Fit a linear model with numpy
a, b = np.polyfit(X_sample, Y_sample, deg=1)
F_fit = lambda x: a * x + b
residuals = Y_sample - F_fit(X_sample)
RSE = np.sqrt(np.sum(residuals ** 2) / (N - 2)) # Residual Standard Error
SE = RSE * np.sqrt(1 / N + (X - X.mean())**2 / np.sum((X_sample - X_sample.mean())**2))
fig, ax = plt.subplots(figsize=cm2inch(onecol_wth, onecol_wth * 0.7))
ax.errorbar(x=X_sample, y=Y_sample, yerr=NOISE_STD, color="茶色", fmt=".", elinewidth=0.6, markersize=4, zorder=0)
ax.fill_between(X, F_fit(X) - SE, F_fit(X) + SE, facecolor="天缥", edgecolor=None, alpha=0.7, zorder=1)
ax.plot(X, F_fit(X), color="空青", label="Fitted line", zorder=3)
ax.plot(X, F(X), color="娇红", ls="dotted", label="True line", zorder=4)
ax.set_xlabel("$x$")
ax.set_ylabel("$y$")
ax.set_ylim(bottom=-25, top=40)
ax.set_xlim(left=0, right=10)
ax.legend(loc="lower right", prop={"family": "DejaVu Serif"})
```
</details>
## LICENSE
This package is licensed under the [MIT License](https://github.com/jinyiliu/cmplstyle/blob/main/LICENSE).
Raw data
{
"_id": null,
"home_page": null,
"name": "cmplstyle",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.11",
"maintainer_email": "Jinyi Liu <liujy0129@gmail.com>",
"keywords": "color palette, matplotlib, scientific plotting, traditional Chinese color",
"author": null,
"author_email": "Jinyi Liu <liujy0129@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/c9/f0/be912ae20c911f767a0d77602b0f2ca321efa126e1c19630c913a212090f/cmplstyle-0.7.0.tar.gz",
"platform": null,
"description": "# cmplstyle\n\nA Python package providing matplotlib style for scientific plotting with traditional Chinese color palette.\n\n## Installation\nYou can install the package using pip:\n```bash\npip install cmplstyle\n```\n\n## Features\n\n- A collection of 365 traditional Chinese colors.\n- Optmised matplotlib style for scientific plotting.\n- Small handy functions for helping scientific plotting.\n\n## Traditional Chinese Colors (TCC)\n\nOur color collection is sourced from the reference [\u300a\u4e2d\u56fd\u4f20\u7edf\u8272\uff1a\u56fd\u6c11\u7248\u8272\u5361\u300b](https://www.douban.com/doubanapp/dispatch/book/35951952?dt_dapp=1) by \u90ed\u6d69, featuring hues widely used in traditional Chinese art and design. See [here](https://jinyiliu.github.io/2025/08/13/cmplstyle/TCC_ncols_5.pdf) for a complete color reference.\n\nThe color names are in Chinese and their HEX color values are stored in the `cmplstyle.TCC` dictionary. Once the package is imported, the colors can be accessed easily by their names. For example,\n```python\nimport cmplstyle\nimport seaborn\nseaborn.palplot([\"\u7fa4\u9752\", \"\u897f\u5b50\", \"\u80ed\u8102\", \"\u6842\u9ec4\", \"\u82cd\u82cd\", \"\u9752\u9a8a\", \"\u5b98\u7eff\", \"\u7c73\u6c64\u5a07\", \"\u6ca7\u6d6a\", \"\u6885\u5b50\u9752\", \"\u77f3\u69b4\u88d9\"])\n```\nwill plot a color palette with the specified colors in the list:\n\n\n\nFor readers unfamiliar with Chinese characters, the colors can also be accessed by the numbered indices (`TCC_1` through `TCC_365`). See [here](https://jinyiliu.github.io/2025/08/13/cmplstyle/TCC_indexed_ncols_5.pdf) for a complete indexed color reference.\n\nThe package provides conversions between Chinese color names and their `TCC_` indexed names: use `cmplstyle.color_index_to_name` to retrieve the Chinese name for a given `TCC_` index, and `cmplstyle.index_name_to_color` to find the corresponding `TCC_` index for a Chinese color name.\n\n## Built-in Matplotlib style\n\nThe package includes a built-in Matplotlib style. Activate it with:\n```python\nimport cmplstyle\ncmplstyle.use_builtin_mplstyle()\n```\n\n### Example: Linear regression plot\n\n\n\n<details>\n<summary>View Plotting Code</summary>\n\n```python\nimport numpy as np\nimport matplotlib.pyplot as plt\nimport cmplstyle\nfrom cmplstyle import onecol_wth, cm2inch\n\ncmplstyle.use_builtin_mplstyle()\nnp.random.seed(20)\n\nF = lambda x: 2.0 * x + 3.0\nX = np.linspace(0, 10, 100)\nN = 15 # sample size\nY_NOISE_STD_MIN = 5.0\nY_NOISE_STD_MAX = 15.0\n\nX_sample = np.random.normal(loc=5, scale=2, size=N)\nY_sample = F(X_sample)\nNOISE_STD = np.random.uniform(Y_NOISE_STD_MIN, Y_NOISE_STD_MAX, size=N)\nY_sample += np.random.normal(size=N) * NOISE_STD\n\n# Fit a linear model with numpy\na, b = np.polyfit(X_sample, Y_sample, deg=1)\nF_fit = lambda x: a * x + b\nresiduals = Y_sample - F_fit(X_sample)\nRSE = np.sqrt(np.sum(residuals ** 2) / (N - 2)) # Residual Standard Error\nSE = RSE * np.sqrt(1 / N + (X - X.mean())**2 / np.sum((X_sample - X_sample.mean())**2))\n\n\nfig, ax = plt.subplots(figsize=cm2inch(onecol_wth, onecol_wth * 0.7))\nax.errorbar(x=X_sample, y=Y_sample, yerr=NOISE_STD, color=\"\u8336\u8272\", fmt=\".\", elinewidth=0.6, markersize=4, zorder=0)\nax.fill_between(X, F_fit(X) - SE, F_fit(X) + SE, facecolor=\"\u5929\u7f25\", edgecolor=None, alpha=0.7, zorder=1)\nax.plot(X, F_fit(X), color=\"\u7a7a\u9752\", label=\"Fitted line\", zorder=3)\nax.plot(X, F(X), color=\"\u5a07\u7ea2\", ls=\"dotted\", label=\"True line\", zorder=4)\n\nax.set_xlabel(\"$x$\")\nax.set_ylabel(\"$y$\")\nax.set_ylim(bottom=-25, top=40)\nax.set_xlim(left=0, right=10)\nax.legend(loc=\"lower right\", prop={\"family\": \"DejaVu Serif\"})\n```\n\n</details>\n\n## LICENSE\nThis package is licensed under the [MIT License](https://github.com/jinyiliu/cmplstyle/blob/main/LICENSE).\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A Python package providing matplotlib style for scientific plotting with traditional Chinese color palette.",
"version": "0.7.0",
"project_urls": {
"Homepage": "https://github.com/jinyiliu/cmplstyle",
"Issues": "https://github.com/jinyiliu/cmplstyle/issues"
},
"split_keywords": [
"color palette",
" matplotlib",
" scientific plotting",
" traditional chinese color"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "afc3bef67f9051cb96f2c34c9272d6894d8f1d3457e789f4c66c984f8d665930",
"md5": "d9c9afb18f7884f2f7ba43612621b191",
"sha256": "8b4f01bf6ce2ce66074a184bb14f5c8e3ec76f0107a310ffc86821bc2d8b5954"
},
"downloads": -1,
"filename": "cmplstyle-0.7.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d9c9afb18f7884f2f7ba43612621b191",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.11",
"size": 41151224,
"upload_time": "2025-08-14T22:30:10",
"upload_time_iso_8601": "2025-08-14T22:30:10.067478Z",
"url": "https://files.pythonhosted.org/packages/af/c3/bef67f9051cb96f2c34c9272d6894d8f1d3457e789f4c66c984f8d665930/cmplstyle-0.7.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "c9f0be912ae20c911f767a0d77602b0f2ca321efa126e1c19630c913a212090f",
"md5": "7d6ba917f283dd0f493436c040bebdd6",
"sha256": "d21ce092d489e7f544c0b506f7cc896b772e6104d590495dccdb9a6cf6cb91d4"
},
"downloads": -1,
"filename": "cmplstyle-0.7.0.tar.gz",
"has_sig": false,
"md5_digest": "7d6ba917f283dd0f493436c040bebdd6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.11",
"size": 41141131,
"upload_time": "2025-08-14T22:30:15",
"upload_time_iso_8601": "2025-08-14T22:30:15.171261Z",
"url": "https://files.pythonhosted.org/packages/c9/f0/be912ae20c911f767a0d77602b0f2ca321efa126e1c19630c913a212090f/cmplstyle-0.7.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-14 22:30:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jinyiliu",
"github_project": "cmplstyle",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "cmplstyle"
}