A Python package providing matplotlib style for scientific plotting with traditional Chinese color palette.
Project description
cmplstyle
A Python package providing matplotlib style for scientific plotting with traditional Chinese color palette.
Installation
You can install the package using pip:
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 《中国传统色:国民版色卡》 by 郭浩, featuring hues widely used in traditional Chinese art and design. See here 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,
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 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:
import cmplstyle
cmplstyle.use_builtin_mplstyle()
Example: Linear regression plot
View Plotting Code
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"})
LICENSE
This package is licensed under the MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cmplstyle-0.7.0.tar.gz.
File metadata
- Download URL: cmplstyle-0.7.0.tar.gz
- Upload date:
- Size: 41.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d21ce092d489e7f544c0b506f7cc896b772e6104d590495dccdb9a6cf6cb91d4
|
|
| MD5 |
7d6ba917f283dd0f493436c040bebdd6
|
|
| BLAKE2b-256 |
c9f0be912ae20c911f767a0d77602b0f2ca321efa126e1c19630c913a212090f
|
Provenance
The following attestation bundles were made for cmplstyle-0.7.0.tar.gz:
Publisher:
publish-to-test-pypi.yml on jinyiliu/cmplstyle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cmplstyle-0.7.0.tar.gz -
Subject digest:
d21ce092d489e7f544c0b506f7cc896b772e6104d590495dccdb9a6cf6cb91d4 - Sigstore transparency entry: 395738775
- Sigstore integration time:
-
Permalink:
jinyiliu/cmplstyle@2c55dc4f805ce70a39561e662c99b43c49cdd4b7 -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/jinyiliu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@2c55dc4f805ce70a39561e662c99b43c49cdd4b7 -
Trigger Event:
push
-
Statement type:
File details
Details for the file cmplstyle-0.7.0-py3-none-any.whl.
File metadata
- Download URL: cmplstyle-0.7.0-py3-none-any.whl
- Upload date:
- Size: 41.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b4f01bf6ce2ce66074a184bb14f5c8e3ec76f0107a310ffc86821bc2d8b5954
|
|
| MD5 |
d9c9afb18f7884f2f7ba43612621b191
|
|
| BLAKE2b-256 |
afc3bef67f9051cb96f2c34c9272d6894d8f1d3457e789f4c66c984f8d665930
|
Provenance
The following attestation bundles were made for cmplstyle-0.7.0-py3-none-any.whl:
Publisher:
publish-to-test-pypi.yml on jinyiliu/cmplstyle
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
cmplstyle-0.7.0-py3-none-any.whl -
Subject digest:
8b4f01bf6ce2ce66074a184bb14f5c8e3ec76f0107a310ffc86821bc2d8b5954 - Sigstore transparency entry: 395738779
- Sigstore integration time:
-
Permalink:
jinyiliu/cmplstyle@2c55dc4f805ce70a39561e662c99b43c49cdd4b7 -
Branch / Tag:
refs/tags/0.7.0 - Owner: https://github.com/jinyiliu
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-to-test-pypi.yml@2c55dc4f805ce70a39561e662c99b43c49cdd4b7 -
Trigger Event:
push
-
Statement type: