Skip to main content

Scientific matplotlib plot rcParams configuration template python package.

Project description

spt

Scientific matplotlib plot rcParams configuration template python package.


Installation

  • via pip:
pip install spt
  • via git:
pip install git+https://gitee.com/yangsl306/spt.git
  • via source code:
git clone https://gitee.com/yangsl306/spt.git
cd spt

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

# editable mode
pip install -e .
  • update:
pip install -U spt

Usage

set_plot_params()

  • code:
import matplotlib.pyplot as plt
from spt.plot_params import set_plot_params

...

set_plot_params()

fig, ax = plt.subplots()

...

set_roman_plot_params()

  • requirements:

To use Times New Roman font, you need to do:

# copy roman-ttf fonts to your matplotlib font path in specific conda env
cp roman-ttf/* <conda_env>/lib/pythonXXX/site-packages/matplotlib/mpl-data/fonts/ttf/

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

  • code:
import matplotlib.pyplot as plt
from spt.plot_params import set_roman_plot_params

...

set_roman_plot_params()

fig, ax = plt.subplots()

...

Chinese characters plot

  • requirements:

To use Chinese(SimHei 黑体) font, you need to do:

# copy SimHei-ttf fonts to matplotlib font path in specific conda env
cp chinese-config/chinese-ttf/* <conda_env>/lib/pythonXXX/site-packages/matplotlib/mpl-data/fonts/ttf/

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

# copy modified matplotlibrc file
cp chinese-config/matplotlibrc <conda_env>/lib/pythonXXX/site-packages/matplotlib/mpl-data/

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

matplotlibrc modification:

# origin 
font.family:  sans-serif
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.family:  sans-serif
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

  • code:
import matplotlib.pyplot as plt
from spt.plot_params import set_roman_plot_params

...

set_roman_plot_params()

fig, ax = plt.subplots()

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

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

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

...

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.1.tar.gz (4.8 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.1-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: spt-0.2.1.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for spt-0.2.1.tar.gz
Algorithm Hash digest
SHA256 011c443ebf4b4c66bb4bc9e7632b434f4d348a1b792fe9e6267f76f3fec04e19
MD5 57ff8ccdb75ca600bc6df9fc3c41af0b
BLAKE2b-256 eb282a1906892d0df377ccda823c0c552336ccfab6ee6907db09e135e322461a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: spt-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for spt-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 66975434fc4c20c855a17879e48db8490bd1483a43483051aee90e7c42c4a06c
MD5 5c3e717fc3c17435ad23ebd5891d6193
BLAKE2b-256 636d88760fcdcc3a4b74df7921b3b32c93966690ee4db7be3da792844e91f9f5

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