Skip to main content

standardized accessible plots

Project description

MyFigure Module

A class for standardized accessible scientific plots.

Documentation Status

Python CI

Overview

MyFigure is a Python module tailored for creating and customizing sophisticated visualizations with Matplotlib and Seaborn. It offers an intuitive interface to streamline figure setup, axis configuration, and style management, making it ideal for both simple plots and complex graphical representations in publications and presentations.

Features

  • Seaborn and Matplotlib Integration: Leverages the advanced styling and plotting capabilities of both Seaborn and Matplotlib to produce beautiful, scientific-grade figures.
  • Default Keyword Arguments: Supports easy customization and flexibility by allowing default configurations that can be overridden according to user needs.
  • Broadcast Keyword Arguments: Automatically broadcasts single values across multiple axes or applies unique values per axis, enhancing customization without additional code for each axis.
  • Automatic Axis Management: Always creates axes as a list, simplifying access and manipulation (e.g., mf.axs[0]), including support for twinx without raising exceptions.
  • Automatic Application of Hatches: Applies hatch patterns to bars in bar plots automatically, improving visibility in colorblind-friendly and black-and-white printouts.
  • Annotate Outliers: Offers functionality to annotate outliers to address scaling issues with a few outlying data points.
  • Edge Padding in Limits: Automatically adds a 5% padding to x_lim, y_lim, and yt_lim to avoid the "Excel-effect" where lines touch the edges of the plot.
  • Legend Integration: Seamlessly integrates legends from multiple axes and twinx in a unified view.
  • Consistent Subplot Annotations: Automatically places letters or annotations in subplots to ensure consistent location across figures.
  • Label Rotation and Anchoring: When labels on the x-axis are rotated, they are anchored on their right to enhance readability.
  • Mask Insignificant Data: Temporarily masks data in bar plots where the error (standard deviation) is greater than the mean, applying a transparency effect to highlight significant results.
  • Inset Plots: Simplifies the creation of inset plots within larger axes for detailed examinations of data subsets.
  • Flexible Saving Options: Allows figures to be saved in various formats including PNG, PDF, SVG, EPS, and TIFF, with options for resolution settings and transparency. This provides versatility for different publishing needs and ensures high-quality outputs.

Installation

Install MyFigure using pip:

pip install myfigure

Documentation

Check out the documentation.

Examples

Examples are available in the examples folder. To run examples:

  1. Install myfigure in your Python environment
  2. Download or copy-paste the example code in your editor
  3. Run the code
  4. If you run the scripts as Jupyter Notebooks, replace the relative path at the beginning of the example with the absolute path to the folder where you want to save the plots.

How to use MyFigure inside functions

# minimum example of function that uses MyFigure to plot its results
def function_using_myfigure(
    your_other_parameters,
    **kwargs,
) -> MyFigure:

    # core computation of the function, to compute the data that
    # will need to be plotted using myfunction

    # if you want to specify a different out_path for the output of this function
    out_path = your_alternative_path  # (using plib)
    out_path.mkdir(parents=True, exist_ok=True)  # create the folder if missing

    # example of default parameter that are specific for this function
    default_kwargs = {
        "height": 4,  # this can be changed, but the default is 4
        "width": 4,  # this can be changed, but the default is 4
        "y_lab": "very_specific_y_lab",  # this can be changed, but the default is "very_specific_y_lab"
    }
    # Update kwargs with the default key-value pairs if the key is not present in kwargs
    kwargs = {**default_kwargs, **kwargs}

    myfig = MyFigure(
        rows=1,  # this cannot be modified, function_using_myfigure(rows=2) gives an error
        cols=1,  # this cannot be modified, function_using_myfigure(rows=2) gives an error
        **kwargs, # this ensures full customization of the object
    )
    myfig.save_figure()
    # it is advisable to return the object so that furter modificaiton can be performed
    # outside the function if needed (then calling again myfig.save_figure() will simply overwrite the
    # version of the figure since the output path is stored in myfig)
    return myfig


# how to call the function
mf_default = function_using_myfigure()  # with default values
# %%
mf_non_default = function_using_myfigure(
    x_lim=(0, 1), height=6, x_lab="a", y_lab="another_specific_label"
) # customized
#
mf = function_using_myfigure()
mf.axs[0].plot([1], [1])  # something that was impossible inside the function
mf.save_figure()

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

myfigure-1.0.1.tar.gz (14.1 kB view details)

Uploaded Source

Built Distribution

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

myfigure-1.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file myfigure-1.0.1.tar.gz.

File metadata

  • Download URL: myfigure-1.0.1.tar.gz
  • Upload date:
  • Size: 14.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for myfigure-1.0.1.tar.gz
Algorithm Hash digest
SHA256 6d95d35f860f6fce7bf412c3d95c77a282364c6999578f7bd88fd25d7172e912
MD5 6525b7d16547e5cfab06961b9091e929
BLAKE2b-256 2cf2abbbefa89046ecc82f6c19b2b63b226fb038d35c07f67b5bb49536094d9b

See more details on using hashes here.

File details

Details for the file myfigure-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: myfigure-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.9.19

File hashes

Hashes for myfigure-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5733c91c520347b13fb2da91b08ba62a27e44fce5e0fa9a904fc35914d224bad
MD5 e341693570bdaf30e60ad4104fa6280c
BLAKE2b-256 4aeaccefde171737033c737abd3bd6f3e5f6db78605b90166ceda3d8f50f05f6

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