Skip to main content

FaSt_Fig

FaSt_Fig is a wrapper for matplotlib that provides a simple interface for fast and easy plotting.

Key features:

  • Predefined templates for consistent styling
  • Figure instantiation in a class object
  • Simplified plotting methods with smart defaults
  • Automatic handling of DataFrames
  • Context manager support for clean resource management
  • Type hints and logging for better development experience

Installation

pip install fast_fig

Basic Usage

from fast_fig import FFig

# Simple example
data = np.array([[1,2,3,4,5],[2,4,6,8,10]])
fig = FFig()
fig.plot(data)
fig.show()

# Use large template and save figure to multiple formats
fig = FFig('l')
fig.plot(data)
fig.save('plot.png', 'pdf')

Context Manager

FaSt_Fig can be used as a context manager for automatic resource cleanup:

with FFig('l', nrows=2, sharex=True) as fig:  # Large template, 2 rows sharing x-axis
    fig.plot([1, 2, 3], label="First")  # Plot in first axis/subplot
    fig.title("First plot")
    fig.next_axis()  # Switch to second axis/subplot
    fig.plot([0, 1, 2], [0, 1, 4], label="Second")  # Plot with x,y data
    fig.legend()  # Add legend
    fig.grid()  # Add grid
    fig.xlabel("X values")  # Label x-axis
    fig.save("plot.png", "pdf")  # Save as PNG and PDF
    # Figure automatically closed when exiting the with block

Plot Types

FaSt_Fig supports all plots of matplotlib. The following plots have adjusted settings to improve their use.

# Bar plots
fig.bar_plot(x, height)

# Logarithmic scales
fig.semilogx(x, y)  # logarithmic x-axis
fig.semilogy(x, y)  # logarithmic y-axis

# 2D plots
x, y = np.meshgrid(np.linspace(-2, 2, 100), np.linspace(-2, 2, 100))
z = np.exp(-(x**2 + y**2))

fig.pcolor(z)  # pseudocolor plot
fig.pcolor_log(z)  # pseudocolor with logarithmic color scale
fig.contour(z, levels=[0.2, 0.5, 0.8])  # contour plot
fig.colorbar(label='Values')  # add colorbar

# Scatter plots
fig.scatter(x, y, c=colors, s=sizes)  # scatter plot with colors and sizes

DataFrame Support

FaSt_Fig has built-in support for pandas DataFrames:

import pandas as pd

# Create a DataFrame with datetime index
df = pd.DataFrame({
    'A': [1, 2, 3, 4],
    'B': [2, 4, 6, 8]
}, index=pd.date_range('2024-01-01', periods=4))

fig = FFig()
fig.plot(df)  # Automatic handling:
              # - Each column becomes a line
              # - Column names become labels
              # - Index used as x-axis
              # - Date index sets x-label to "Date"

Matplotlib interaction

FaSt_Fig provides direct access to matplotlib objects through these handlers:

  • fig.current_axis: Current axes instance for active subplot
fig.current_axis.set_yscale('log')  # Direct matplotlib axis methods
  • fig.handle_fig: Figure instance for figure-level operations
fig.handle_fig.tight_layout()  # Adjust layout
  • fig.handle_plot: Current plot instance(s)
fig.handle_plot[0].set_linewidth(2)  # Modify line properties
  • fig.handle_axis: All axes instances for subplot access
fig.handle_axis[0].set_title('First subplot')  # Access any subplot

These handlers provide full access to matplotlib's functionality when needed.

Presets

FaSt_Fig comes with built-in presets that control figure appearance. Available preset templates:

  • m (medium): 15x10 cm, sans-serif font, good for general use
  • s (small): 10x8 cm, sans-serif font, suitable for small plots
  • l (large): 20x15 cm, sans-serif font, ideal for presentations
  • ol (Optics Letters): 8x6 cm, serif font, optimized for single line plots
  • oe (Optics Express): 12x8 cm, serif font, designed for equation plots
  • square: 10x10 cm, serif font, perfect for square plots

Each preset defines:

  • width: Figure width in cm
  • height: Figure height in cm
  • fontfamily: Font family (serif or sans-serif)
  • fontsize: Font size in points
  • linewidth: Line width in points

You can use presets in three ways:

  1. Use a built-in preset:
fig = FFig('l')  # Use large preset
  1. Load custom presets from a file:
fig = FFig('m', presets='my_presets.yaml')  # YAML format
fig = FFig('m', presets='my_presets.json')  # or JSON format
  1. Override specific preset values:
fig = FFig('m', width=12, fontsize=14)  # Override width and fontsize

The preset system also includes color sequences and line styles that cycle automatically when plotting multiple lines:

  • Default colors: blue, red, green, orange
  • Default line styles: solid (-), dashed (--), dotted (:), dash-dot (-.)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

Licensed under MIT License. See LICENSE for details.

Author

Written by Fabian Stutzki (fast@fast-apps.de)

For more information, visit www.fast-apps.de

Metadata

Release files for fast-fig 0.7.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fast-fig 0.7.0
File Size Uploaded
fast_fig-0.7.0.tar.gz 21.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for fast-fig 0.7.0
File Interpreter ABI Platform
fast_fig-0.7.0-py3-none-any.whl Python 3 none any Details

Total release size: 38.4 kB

Release files / fast_fig-0.7.0.tar.gz

Download URL fast_fig-0.7.0.tar.gz
Size 21.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e9c86c9902fd2040b6b9aba2b0ba92248e540e2f2670dea936125696c0698b9c
BLAKE2b-256 checksum
How to use checksums
f8732a0accc0ff3024c97692d6c40525f5b46fcdd0bad22dd9afa10e48d4af02
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.12

Release files / fast_fig-0.7.0-py3-none-any.whl

Download URL fast_fig-0.7.0-py3-none-any.whl
Size 16.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
166ce40f94fc3baec7f33be57be7e5c81a69e85eafdce5735c5b415620036be0
BLAKE2b-256 checksum
How to use checksums
9244e5cd63e68121a96b1c28facb23b664eff2bc1f9517d57eee51d23f1bad01
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.7.12

Release history Release notifications | RSS feed

0.8.4

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

This release

0.7.0 This release

2 release files

0.6.1

2 release files

0.6.0

2 release files

0.5.5

2 release files

0.5.4

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page