PltSci
一个用于简化 matplotlib 绘图参数设置的 Python 工具库。
安装
pip install pltsci
快速开始
示例:创建一个全宽的科学绘图
from pltsci import whole_plot_set, set_ticks, cm
import matplotlib.pyplot as plt
import numpy as np
# 设置全局绘图参数
whole_plot_set() # 全宽图片参数设置
fig, ax = plt.subplots(figsize=(15 * cm, 10 * cm), dpi=300) # 创建图形 (使用厘米单位)
# 创建示例数据
x = np.linspace(0, 10, 100)
y = np.sin(x)
ax.plot(x, y, label="$y=\\sin(x)$")
# 设置坐标轴范围和刻度
set_ticks(ax, xrange=(0, 10, 2), yrange=(-1.5, 1.5, 0.5))
# 添加标签和图例
ax.set_xlabel("x", fontsize=12)
ax.set_ylabel("y", fontsize=12)
ax.legend()
plt.tight_layout()
fig.savefig("examples/whole_plot.svg", bbox_inches="tight")
结果:
示例:创建一个半宽的科学绘图
from pltsci import whole_plot_set, half_plot_set, set_ticks, cm
import matplotlib.pyplot as plt
import numpy as np
# 设置全局绘图参数
whole_plot_set() # 全宽图片参数设置,即使是用半宽图,也建议先调用此函数设置全局参数
fig, ax = plt.subplots(figsize=(7 * cm, 5 * cm), dpi=300) # 创建图形 (使用厘米单位)
half_plot_set(ax) # 半宽图片参数设置
# 创建示例数据
x = np.linspace(0, 10, 100)
y = np.exp(x)
ax.plot(x, y, label="$y=e^x$")
# 设置坐标轴范围和刻度
set_ticks(ax, xrange=(0, 10, 2), yrange=(0, 22000, 5000))
# 添加标签和图例
ax.set_xlabel("x", fontsize=10)
ax.set_ylabel("y", fontsize=10)
ax.legend(fontsize=8)
plt.tight_layout()
fig.savefig("examples/half_plot.svg", bbox_inches="tight")
# fig.savefig("examples/half_plot.jpg", bbox_inches="tight", dpi=1200) # 位图记得设置高分辨率
结果:
API 参考
whole_plot_set(font=None, math_font="stix")
设置全局绘图参数,包括字体、刻度方向、图例样式等。
font: 字体列表,默认为["Times New Roman", "SimSun"]math_font: 数学公式字体,默认为"stix"
set_ticks(ax, xrange=None, yrange=None)
设置坐标轴范围和刻度。
ax: matplotlib 轴对象xrange: x轴范围,格式为(xmin, xmax, xstep)yrange: y轴范围,格式为(ymin, ymax, ystep)majorMaxNLocator: 主刻度最大数量,默认为NoneminorLocator: 每两个主刻度之间的次刻度数量,默认为 2have_x_major: 是否显示 x 轴主刻度,默认为 Truehave_y_major: 是否显示 y 轴主刻度,默认为 Truehave_x_label: 是否显示 x 轴刻度值,默认为 Truehave_y_label: 是否显示 y 轴刻度值,默认为 True
half_plot_set(ax)
设置坐标轴线宽和刻度样式,适用于密集布局的图表。
ax: matplotlib 轴对象
cm
厘米到英寸转换工具。
# 两种使用方式
fig, ax = plt.subplots(figsize=(15 * cm, 10 * cm))
# 或者
fig, ax = plt.subplots(figsize=(cm(15), cm(10)))
许可证
MIT License - 详见 LICENSE 文件。
贡献
欢迎提交 Issue 和 Pull Request!
Metadata
Release files for pltsci 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pltsci-0.2.2.tar.gz | 5.1 kB | Without provenance | Details for pltsci-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pltsci-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for pltsci-0.2.2-py3-none-any.whl |
Total release size: 11.2 kB
Release files / pltsci-0.2.2.tar.gz
| Download URL | pltsci-0.2.2.tar.gz |
|---|---|
| Size | 5.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
51acf97e47a79df6f6a088e66e817bfd6d6435d3039c07bd051884b059205d04
|
|
BLAKE2b-256 checksum How to use checksums |
fefa4e2fc848006ef48698b3490d99630dda097c00db931c64b36968a502870a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Release files / pltsci-0.2.2-py3-none-any.whl
| Download URL | pltsci-0.2.2-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
431ac7c9bcb714a6db461afdc14ff185fc109607b6443866ed2451754213b06a
|
|
BLAKE2b-256 checksum How to use checksums |
7719b4693dceac6d01064573e6b88e1c7e5500341f6b0fdab872fd422c59ee16
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.2
|
Security for pltsci 0.2.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.