Skip to main content

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:

  1. Registry Check: First checks matplotlib's font registry (fastest)
  2. System Search: Searches system fonts by checking properties
  3. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

myplot-0.1.1.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

myplot-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

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

Hashes for myplot-0.1.1.tar.gz
Algorithm Hash digest
SHA256 4f2f745d52537afc6d3254df8e5d276fdb4eb24c1e604200bdb9a3138f33ed0e
MD5 952efd36fa73d311d0b59e39b21fe2ad
BLAKE2b-256 04a06d885d695168a51b2a9b0ef69c229e9af8473aedf9917cb9096005183eaf

See more details on using hashes here.

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

Hashes for myplot-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 098ade3b0b13975d272ed241567c52ab10263ff9400bdcfe16a3e16a3ae89a1a
MD5 604d96ebd4841b0576c697344caa6026
BLAKE2b-256 60befaea9913dbdc56e921f709a3f854ad6b64e00f8b49ead2a36773442cd402

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