fast_fig


Namefast_fig JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://www.fast-apps.de
SummaryFaSt_Fig is a wrapper for matplotlib with templates.
upload_time2025-01-26 19:20:08
maintainerNone
docs_urlNone
authorFabian Stutzki
requires_python<4.0,>=3.9
licenseMIT
keywords matplotlib figure
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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:

```python
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.

```python
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:

```python
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.

```python
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:

```python
# 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):

```python
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.
```python
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.
```python
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.
```python
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.
```python
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:
```python
fig = FFig('l')  # Use large preset
```

2. Load custom presets from a file:
```python
fig = FFig('m', presets='my_presets.yaml')  # YAML format
fig = FFig('m', presets='my_presets.json')  # or JSON format
```

3. Override specific preset values:
```python
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


            

Raw data

            {
    "_id": null,
    "home_page": "https://www.fast-apps.de",
    "name": "fast_fig",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "matplotlib, figure",
    "author": "Fabian Stutzki",
    "author_email": "fast@fast-apps.de",
    "download_url": "https://files.pythonhosted.org/packages/13/ab/8bf39bb3f9a537c74031ec12f6f6c73cd07eac2bbf75229bf7fe94814f44/fast_fig-0.6.0.tar.gz",
    "platform": null,
    "description": "# FaSt_Fig\nFaSt_Fig is a wrapper for matplotlib that provides a simple interface for fast and easy plotting.\n\nKey functions:\n- figure instantiation in a class object\n- predefinied templates\n- simplified handling (e.g. plot with vectors)\n- save to multiple file formats\n\n## Usage\nAfter installation by `pip install fast_fig` you can start with a very simple example:\n\n```python\nfrom fast_fig import FFig\nfig = FFig()\nfig.plot()\nfig.show()\n```\n\nYou can also start with your own data, change to a large templateand save the figure.\n\n```python\ndata = np.array([[1,2,3,4,5],[2,4,6,8,10]])\nfig = FFig('l')\nfig.plot(data)\nfig.save('test_fig1.png') # save figure\n```\n\nFaSt_Fig can also be used as a context manager, which automatically handles figure cleanup:\n\n```python\nwith FFig('m') as fig:\n    fig.plot(data)\n    fig.save('plot.png')\n    # Figure automatically closed when exiting the with block\n```\n\nFaSt_Fig allows for more complex behavior with multiple subplots, legend, grid and saving to multiple files at once.\n\n```python\nfig = FFig('l',nrows=2) # create figure with two rows and template 'l'\nfig.plot([1,2,3,1,2,3,4,1,1]) # plot first data set\nfig.title('First data set') # set title for subplot\nfig.subplot() # set focus to next subplot/axis\nfig.plot([0,1,2,3,4],[0,1,1,2,3],label=\"random\") # plot second data set\nfig.legend() # generate legend\nfig.grid() # show translucent grid to highlight major ticks\nfig.xlabel('Data') # create xlabel for second axis\nfig.save('test_fig2.png','pdf') # save figure to png and pdf\n```\n\n## Plot Types\n\nFaSt_Fig supports various plot types beyond basic line plots:\n\n```python\n# Bar plots\nfig.bar_plot(x, height)\n\n# Logarithmic scales\nfig.semilogx(x, y)  # logarithmic x-axis\nfig.semilogy(x, y)  # logarithmic y-axis\n\n# 2D plots\nx, y = np.meshgrid(np.linspace(-2, 2, 100), np.linspace(-2, 2, 100))\nz = np.exp(-(x**2 + y**2))\n\nfig.pcolor(z)  # pseudocolor plot\nfig.pcolor_log(z)  # pseudocolor with logarithmic color scale\nfig.contour(z, levels=[0.2, 0.5, 0.8])  # contour plot\nfig.colorbar(label='Values')  # add colorbar\n\n# Scatter plots\nfig.scatter(x, y, c=colors, s=sizes)  # scatter plot with colors and sizes\n```\n\n## DataFrame Support\n\nFaSt_Fig has built-in support for pandas DataFrames (optional dependency):\n\n```python\nimport pandas as pd\n\n# Create a DataFrame\ndf = pd.DataFrame({\n    'A': [1, 2, 3, 4],\n    'B': [2, 4, 6, 8]\n}, index=pd.date_range('2024-01-01', periods=4))\n\n# Plot DataFrame\nfig = FFig()\nfig.plot(df)  # Each column becomes a line, index is x-axis\n# Column names are used as labels\n# Date index automatically sets x-label to \"Date\"\n```\n\n## Matplotlib Handles\n\nFaSt_Fig provides direct access to the underlying matplotlib objects through these handles:\n\n- `fig.current_axis`: The currently active Axes object. Use this for axis-specific operations like setting scales, limits, or adding specialized plots.\n```python\nfig.current_axis.set_yscale('log')  # Set y-axis to logarithmic scale\n```\n\n- `fig.handle_fig`: The main Figure object. Use this for figure-level operations like adjusting layout or adding subfigures.\n```python\nfig.handle_fig.tight_layout()  # Adjust subplot parameters for better fit\n```\n\n- `fig.handle_plot`: List of Line2D objects from the most recent plot. Use this to modify line properties after plotting.\n```python\nfig.handle_plot[0].set_linewidth(2)  # Change line width of first line\n```\n\n- `fig.handle_axis`: Array of all Axes objects. Use this to access any subplot directly.\n```python\nfig.handle_axis[0].set_title('First subplot')  # Set title of first subplot\n```\n\nThese handles give you full access to matplotlib's functionality when you need more control than FaSt_Fig's simplified interface provides.\n\n## Presets\n\nFaSt_Fig comes with built-in presets that control figure appearance. Available preset templates:\n\n- `m` (medium): 15x10 cm, sans-serif font, good for general use\n- `s` (small): 10x8 cm, sans-serif font, suitable for small plots\n- `l` (large): 20x15 cm, sans-serif font, ideal for presentations\n- `ol` (Optics Letters): 8x6 cm, serif font, optimized for single line plots\n- `oe` (Optics Express): 12x8 cm, serif font, designed for equation plots\n- `square`: 10x10 cm, serif font, perfect for square plots\n\nEach preset defines:\n- `width`: Figure width in cm\n- `height`: Figure height in cm\n- `fontfamily`: Font family (serif or sans-serif)\n- `fontsize`: Font size in points\n- `linewidth`: Line width in points\n\nYou can use presets in three ways:\n\n1. Use a built-in preset:\n```python\nfig = FFig('l')  # Use large preset\n```\n\n2. Load custom presets from a file:\n```python\nfig = FFig('m', presets='my_presets.yaml')  # YAML format\nfig = FFig('m', presets='my_presets.json')  # or JSON format\n```\n\n3. Override specific preset values:\n```python\nfig = FFig('m', width=12, fontsize=14)  # Override width and fontsize\n```\n\nThe preset system also includes color sequences and line styles that cycle automatically when plotting multiple lines:\n- Default colors: blue, red, green, orange\n- Default line styles: solid (-), dashed (--), dotted (:), dash-dot (-.)\n\n## Final words\n\nWritten by Fabian Stutzki, fast@fast-apps.de\n\nLicensed under MIT\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "FaSt_Fig is a wrapper for matplotlib with templates.",
    "version": "0.6.0",
    "project_urls": {
        "Homepage": "https://www.fast-apps.de"
    },
    "split_keywords": [
        "matplotlib",
        " figure"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "040f8f1b2d1d2fa2a2aa53877a7524248c88104e4fc842f8162083ddee804004",
                "md5": "1faafb0572816d698ef573d445e5882f",
                "sha256": "eb8f7f5dfffcc6725910920e72cdc152e058bd14debdbcf374bb856edf031702"
            },
            "downloads": -1,
            "filename": "fast_fig-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "1faafb0572816d698ef573d445e5882f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 15458,
            "upload_time": "2025-01-26T19:20:06",
            "upload_time_iso_8601": "2025-01-26T19:20:06.221139Z",
            "url": "https://files.pythonhosted.org/packages/04/0f/8f1b2d1d2fa2a2aa53877a7524248c88104e4fc842f8162083ddee804004/fast_fig-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "13ab8bf39bb3f9a537c74031ec12f6f6c73cd07eac2bbf75229bf7fe94814f44",
                "md5": "ef167f9eb5b73f612f110c4937049b02",
                "sha256": "c7b72b0fa67a5e29f122ba270a6f4a40b1b215190467d168b186e4775aa23057"
            },
            "downloads": -1,
            "filename": "fast_fig-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ef167f9eb5b73f612f110c4937049b02",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 15718,
            "upload_time": "2025-01-26T19:20:08",
            "upload_time_iso_8601": "2025-01-26T19:20:08.260057Z",
            "url": "https://files.pythonhosted.org/packages/13/ab/8bf39bb3f9a537c74031ec12f6f6c73cd07eac2bbf75229bf7fe94814f44/fast_fig-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-01-26 19:20:08",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "fast_fig"
}
        
Elapsed time: 4.32767s