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 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 (-.)
Final words
Written by Fabian Stutzki, fast@fast-apps.de
Licensed under MIT
Metadata
Release files for fast-fig 0.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fast_fig-0.6.0.tar.gz | 15.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fast_fig-0.6.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.2 kB
Release files / fast_fig-0.6.0.tar.gz
| Download URL | fast_fig-0.6.0.tar.gz |
|---|---|
| Size | 15.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7b72b0fa67a5e29f122ba270a6f4a40b1b215190467d168b186e4775aa23057
|
|
BLAKE2b-256 checksum How to use checksums |
13ab8bf39bb3f9a537c74031ec12f6f6c73cd07eac2bbf75229bf7fe94814f44
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0
|
Release files / fast_fig-0.6.0-py3-none-any.whl
| Download URL | fast_fig-0.6.0-py3-none-any.whl |
|---|---|
| Size | 15.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb8f7f5dfffcc6725910920e72cdc152e058bd14debdbcf374bb856edf031702
|
|
BLAKE2b-256 checksum How to use checksums |
040f8f1b2d1d2fa2a2aa53877a7524248c88104e4fc842f8162083ddee804004
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.0.1 CPython/3.13.1 Darwin/24.2.0
|