Skip to main content

Scientific Matplotlib plot rcParams configuration template python package.

Project description

spt

PyPi PyPI Downloads Requires Python 3.9+

           _
 ___ _ __ | |_
/ __| '_ \| __|
\__ \ |_) | |_
|___/ .__/ \__|
    |_|

spt: A Scientific Matplotlib plot rcParams configuration template Python package.


Installation

  • via pip:
pip install -U spt

# install spt and examples dependencies
pip install ".[examples]"
  • via git:
pip install git+https://github.com/Bit-Part-Young/spt.git
# or
pip install git+https://gitee.com/yangsl306/spt.git
  • via source code:
git clone https://github.com/Bit-Part-Young/spt.git
# or
git clone https://gitee.com/yangsl306/spt.git

cd spt

# create virtual environment
python -m venv venv
source venv/bin/activate

pip install .
# or
pip install -r requirements.txt

# editable mode
pip install -e .

Usage

Full example codes can be found in examples folder.


fonts

  • Times New Roman: Copy TimesNewRoman*.ttf fonts to ~/.fonts or ~/.local/share/fonts or matplotlib font path in specific conda env, then remove matplotlib cache, relogin.
cp fonts/TimesNewRoman*.ttf ~/.fonts
# or
cp fonts/TimesNewRoman*.ttf ~/.local/share/fonts
# or
cp fonts/TimesNewRoman*.ttf <conda_env>/lib/pythonXXX/site-packages/matplotlib/mpl-data/fonts/ttf/

# remove matplotlib cache
rm -rf ~/.cache/matplotlib

# check fonts
fc-list lang:en | grep -i "Times New Roman"
  • Chinese: Copy SimHei.ttf font to ~/.fonts or ~/.local/share/fonts or matplotlib font path in specific conda env, backup original matplotlibrc file, copy modified matplotlibrc file to mpl-data path, then remove matplotlib cache, relogin.
cp fonts/SimHei.ttf ~/.fonts
# or
cp fonts/SimHei.ttf ~/.local/share/fonts
# or
cp fonts/SimHei.ttf <conda_env>/lib/pythonXXX/site-packages/matplotlib/mpl-data/fonts/ttf/

# backup matplotlibrc file
cp fonts/matplotlibrc <conda_env>/lib/pythonXXX/site-packages/matplotlib/mpl-data/

# remove matplotlib cache
rm -rf ~/.cache/matplotlib

# check fonts
fc-list lang:zh | grep -i "SimHei"

matplotlibrc modification:

# Original
font.sans-serif: DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif
axes.unicode_minus: True  # use Unicode for the minus symbol rather than hyphen.  See

# Modification
font.sans-serif: DejaVu Sans, Bitstream Vera Sans, Computer Modern Sans Serif, Lucida Grande, Verdana, Geneva, Lucid, Arial, Helvetica, Avant Garde, sans-serif, SimHei, Times New Roman, Times
axes.unicode_minus: False  # use Unicode for the minus symbol rather than hyphen.  See

set_plot_params()

  • code snippets (complete script: plot.py):
import matplotlib.pyplot as plt
from spt.plot_params import set_plot_params

...

set_plot_params()
fig, ax = plt.subplots()

...

Figure:

sin.png


set_plot_params() with Times New Roman font

import matplotlib.pyplot as plt
from spt.plot_params import set_plot_params

...

set_plot_params(roman_params=True)
fig, ax = plt.subplots()

...

Figure:

sin_roman.png


  • 3d plot code snippets (complete script: plot_3d.py):
import matplotlib.pyplot as plt
from spt.plot_params import set_plot_params

...

set_plot_params(
    roman_params=True,
    axes_labelpad=15,
    legend_handletextpad=0.0,
    legend_fontsize=22,
    savefig_bbox="standard",
)

fig, ax = plt.subplots(subplot_kw={"projection": "3d"}, figsize=(10, 8))

...

Figure:

scatter_3d.png


Chinese characters plot

import matplotlib.pyplot as plt
from spt.plot_params import set_plot_params

...

set_plot_params(roman_params=True)

fig, ax = plt.subplots()

ax.plot(x, y, label="正弦函数")

ax.set(xlabel="x", ylabel="y")

# legend 字体设置为 SimHei
ax.legend(prop={"family": "SimHei"})

...

Figure

sin_zh.png


Scientific Figure Examples

Figure:

dot_line.png


Figure:

substitution_energy_Nb3Si.png


Figure:

b_fit_cal.png


Figure:

xrd.png

Figure:

AlMoZr_ternary.png

Figure:

AlMoZr_convex_hull.png

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

spt-0.2.6.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spt-0.2.6-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file spt-0.2.6.tar.gz.

File metadata

  • Download URL: spt-0.2.6.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for spt-0.2.6.tar.gz
Algorithm Hash digest
SHA256 ae8d4907f5afe995b9bc1cb5f89a1e2c1c95958df4cbebf8b79a5d652f05d591
MD5 896444f735e202c608240f7dacdf7e24
BLAKE2b-256 4d45ed8a43ddf7b0e7b19dace51b76fcaa3908cf5e3bbccfc19e62a9e2bf6045

See more details on using hashes here.

File details

Details for the file spt-0.2.6-py3-none-any.whl.

File metadata

  • Download URL: spt-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for spt-0.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 d390fd2d8a736800a81786f4b54320faab64852b5a3761956ee4b8551a908597
MD5 936a51a9425cb0eb9674986eee9a75b0
BLAKE2b-256 3458e676846d39f6ea44309c4826aab886c5ccb9644400ae5696d088151a2905

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page