Skip to main content

FaSt_Fig is a wrapper for matplotlib with templates.

Project description

FaSt_Fig

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

Key functions:

  • figure instantiation in a class object
  • predefinied templates
  • simplified handling (e.g. plot with vectors)
  • save to multiple file formats

Usage

After installation by pip install fast_fig you can start with a very simple example:

from fast_fig import FFig
fig = FFig()
fig.plot()
fig.show()

You can also start with your own data, change to a large templateand save the figure.

data = np.array([[1,2,3,4,5],[2,4,6,8,10]])
fig = FFig('l')
fig.plot(data)
fig.save('test_fig1.png') # save figure

FaSt_Fig can also be used as a context manager, which automatically handles figure cleanup:

with FFig('m') as fig:
    fig.plot(data)
    fig.save('plot.png')
    # Figure automatically closed when exiting the with block

FaSt_Fig allows for more complex behavior with multiple subplots, legend, grid and saving to multiple files at once.

fig = FFig('l',nrows=2) # create figure with two rows and template 'l'
fig.plot([1,2,3,1,2,3,4,1,1]) # plot first data set
fig.title('First data set') # set title for subplot
fig.subplot() # set focus to next subplot/axis
fig.plot([0,1,2,3,4],[0,1,1,2,3],label="random") # plot second data set
fig.legend() # generate legend
fig.grid() # show translucent grid to highlight major ticks
fig.xlabel('Data') # create xlabel for second axis
fig.save('test_fig2.png','pdf') # save figure to png and pdf

Plot Types

FaSt_Fig supports various plot types beyond basic line plots:

# 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 (optional dependency):

import pandas as pd

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

# Plot DataFrame
fig = FFig()
fig.plot(df)  # Each column becomes a line, index is x-axis
# Column names are used as labels
# Date index automatically sets x-label to "Date"

Matplotlib Handles

FaSt_Fig provides direct access to the underlying matplotlib objects through these handles:

  • fig.current_axis: The currently active Axes object. Use this for axis-specific operations like setting scales, limits, or adding specialized plots.
fig.current_axis.set_yscale('log')  # Set y-axis to logarithmic scale
  • fig.handle_fig: The main Figure object. Use this for figure-level operations like adjusting layout or adding subfigures.
fig.handle_fig.tight_layout()  # Adjust subplot parameters for better fit
  • fig.handle_plot: List of Line2D objects from the most recent plot. Use this to modify line properties after plotting.
fig.handle_plot[0].set_linewidth(2)  # Change line width of first line
  • fig.handle_axis: Array of all Axes objects. Use this to access any subplot directly.
fig.handle_axis[0].set_title('First subplot')  # Set title of first subplot

These handles give you full access to matplotlib's functionality when you need more control than FaSt_Fig's simplified interface provides.

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 https://www.fast-apps.de

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

fast_fig-0.6.1.tar.gz (21.1 kB view details)

Uploaded Source

Built Distribution

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

fast_fig-0.6.1-py3-none-any.whl (15.8 kB view details)

Uploaded Python 3

File details

Details for the file fast_fig-0.6.1.tar.gz.

File metadata

  • Download URL: fast_fig-0.6.1.tar.gz
  • Upload date:
  • Size: 21.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for fast_fig-0.6.1.tar.gz
Algorithm Hash digest
SHA256 a526797104c7c1d0ce03818cdeb814346d16157a45851dfc4d3fc7ec027ff333
MD5 455e6e27ff57d4936a48b46c28918446
BLAKE2b-256 a008e558528ac3d7a6a98cc2f13de447d911e40489d192d6f52e1dfdee807e0f

See more details on using hashes here.

File details

Details for the file fast_fig-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: fast_fig-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 15.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.7.9

File hashes

Hashes for fast_fig-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 508e9c13268a83673816545f3bb3115726cf1b259308c500b255c96126a8e8b8
MD5 2c80cb019cc0707643b888afa127ead4
BLAKE2b-256 00de12fde7645dc6d5123840a64d71a00f8e3ebe671837b5d429e6424b945972

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