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 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
x = [1,2,3,4,5]
y1 = [2,4,5,6,10]
y2 = [1,3,2,6,9]
# Simple plot example
fig = FFig()
fig.plot(x,y1)
fig.show()
# Use large template and save figure to multiple formats
fig = FFig('l')
fig.plot(x,y)
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, 2.5], label="First") # Plot in first axis/subplot
fig.set_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.set_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.colorbar(label='Values') # add colorbar
fig.pcolor_log(z) # pseudocolor with logarithmic color scale
fig.contour(z, levels=[0.2, 0.5, 0.8]) # contour plot
# 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 subplotfig.handle_fig: Figure instance for figure-level operationsfig.handle_plot: Current plot instance(s)fig.handle_axis: All axes instances for subplot access
fig.current_axis.set_yscale('log') # Direct matplotlib axis methods
fig.handle_fig.tight_layout() # Adjust layout
fig.handle_plot[0].set_linewidth(2) # Modify line properties
fig.handle_axis[0].set_title('First subplot') # Access any subplot
These handles 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 uses(small): 10x8 cm, sans-serif font, suitable for small plotsl(large): 20x15 cm, sans-serif font, ideal for presentationsol(Optics Letters): 8x6 cm, serif font, optimized for single line plotsoe(Optics Express): 12x8 cm, serif font, designed for equation plotssquare: 10x10 cm, serif font, perfect for square plots
Each preset defines:
width: Figure width in cmheight: Figure height in cmfontfamily: Font family (serif or sans-serif)fontsize: Font size in pointslinewidth: Line width in points
You can use presets in three ways:
- Use a built-in preset:
fig = FFig('l') # Use large preset
- 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
- 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
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 fast_fig-0.8.1.tar.gz.
File metadata
- Download URL: fast_fig-0.8.1.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2ac88d0379389bd326b8e3a3eed0bb368622952b65d1d1dfe54af3b240af317a
|
|
| MD5 |
8cd4125e363ef2521e2bf91d13925800
|
|
| BLAKE2b-256 |
1d95a0628db7ac282c0c843816edfe40398d8583b4d47897ae931555f19fdddc
|
File details
Details for the file fast_fig-0.8.1-py3-none-any.whl.
File metadata
- Download URL: fast_fig-0.8.1-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.8.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bf8ffb422dee8f16986ebf23792046222f3643fbc13a18643871ffdf542e1df9
|
|
| MD5 |
946870f4aabbf43bfde0d5a09dcbea9b
|
|
| BLAKE2b-256 |
79ed0afa83c877663895d06bf4917b9036875c9e0bcaed7973ac23c2b0c709e8
|