A uniform plotting module for matplotlib with automatic font detection
Project description
MyPlot
A uniform plotting module for matplotlib with automatic font detection and cross-platform support.
Features
- Uniform Formatting: Consistent plot styling across all your projects
- Automatic Font Detection: Finds and configures Source Han Serif font for Chinese characters
- Cross-Platform Support: Works on Windows, macOS, and Linux
- Easy to Use: Simple decorator interface for creating publication-quality plots
- Built-in Utilities: Radian/degree formatters and other plotting utilities
Installation
pip install -e .
# Using uv
uv add myplot
Quick Start
import myplot
import numpy as np
@myplot.myplot(figsize=(8, 6))
def simple_plot():
x = np.linspace(0, 10, 100)
plt.plot(x, np.sin(x), label='正弦波')
plt.xlabel('x (弧度)')
plt.ylabel('sin(x)')
plt.title('正弦函数图')
plt.legend()
simple_plot()
Font Detection Logic
MyPlot automatically searches for Source Han Serif fonts using an optimized strategy:
- Registry Check: First checks matplotlib's font registry (fastest)
- System Search: Searches system fonts by checking properties
- Project Search: Falls back to project directories if needed
This optimized approach significantly speeds up initialization while maintaining compatibility.
Search Paths:
- Windows:
C:/Windows/Fonts,%LOCALAPPDATA%/Microsoft/Windows/Fonts - macOS:
/System/Library/Fonts,/Library/Fonts,~/Library/Fonts - Linux:
/usr/share/fonts/*,~/.local/share/fonts - Project:
./fonts/,./resources/fonts/,./src/fonts/
If no font is found, it falls back to matplotlib's default settings.
API
myplot Decorator
@myplot.myplot(
figsize=(4.8, 3.6), # Figure size
save=True, # Save automatically
log=True, # Log creation
savename='plot', # Custom filename
config_dir='./config' # Custom config dir
)
def plot():
plt.plot(x, y)
myUtilities
# Radian formatter (e.g., 0.5π)
formatter = myplot.myUtilities.radFormatter()
# Degree formatter (e.g., 90°)
formatter = myplot.myUtilities.degFormatter()
myparams
params = myplot.myparams()
params.put('width', 800)
params['theme'] = 'dark'
Requirements
- Python 3.8+
- matplotlib >= 3.5.0
- numpy >= 1.20.0
License
MIT License
Project details
Release history Release notifications | RSS feed
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 myplot-0.1.1.tar.gz.
File metadata
- Download URL: myplot-0.1.1.tar.gz
- Upload date:
- Size: 7.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4f2f745d52537afc6d3254df8e5d276fdb4eb24c1e604200bdb9a3138f33ed0e
|
|
| MD5 |
952efd36fa73d311d0b59e39b21fe2ad
|
|
| BLAKE2b-256 |
04a06d885d695168a51b2a9b0ef69c229e9af8473aedf9917cb9096005183eaf
|
File details
Details for the file myplot-0.1.1-py3-none-any.whl.
File metadata
- Download URL: myplot-0.1.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.17
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
098ade3b0b13975d272ed241567c52ab10263ff9400bdcfe16a3e16a3ae89a1a
|
|
| MD5 |
604d96ebd4841b0576c697344caa6026
|
|
| BLAKE2b-256 |
60befaea9913dbdc56e921f709a3f854ad6b64e00f8b49ead2a36773442cd402
|