Skip to main content

teeplot automatically saves a copy of rendered Jupyter notebook plots

Project description

teeplot wordmark

teeplot wrangles your data visualizations out of notebooks for you

PyPi docs GitHub stars CI

teeplot’s tee function can wrap your plotting calls to automatically manage matplotlib file output, picking meaningful names based on semantic plotting variables.

# adapted from
import seaborn as sns; from teeplot import teeplot as tp

tp.tee(sns.lmplot,  # plotter
    sns.load_dataset("tips"), col="time", hue="sex", x="total_bill", y="tip",  # fwded kw/args
    teeplot_postprocess=sns.FacetGrid.add_legend)  # teeplot options

Here’s how it works: teeplot’s tee function that acts as a wrapper around your plotting calls. Give tee your plotting function (e.g., sns.lineplot) as the first argument and then add the arguments you want to call it with.

teeplot automatically captures the function and its arguments, calls the plotter as instructed, and then it handles the matplotlib file output for you. It generates descriptive filenames for the saved plots by extracting key information from the plot parameters and arguments. This feature allows you to keep track of your visualizations easily by making the process of saving and cataloging your plots more efficient, systematic and meaningful, taking the hassle out of manual file management.

teeplot contains several advanced features, such as a draftmode flag, which will disable file output globally, and the teeplot_callback kwarg, which delays plot output to allow for figure tweaks. Read on for details.



Example 1

Simple example demonstrating use with pandas built-in plotting.

# adapted from
import pandas as pd; from teeplot import teeplot as tp

age_list = [8, 10, 12, 14, 72, 74, 76, 78, 20, 25, 30, 35, 60, 85]
df = pd.DataFrame({"gender": list("MMMMMMMMFFFFFF"), "age": age_list})

tp.tee(,  # plotter...
    column="age", by="gender", figsize=(4, 3))  # ...forwarded kwargs

Example 2

Example with seaborn showing use of teeplot_callback kwarg to allow for plot tweaks before saving.

# adapted from
from matplotlib import pyplot as plt
import seaborn as sns
from teeplot import teeplot as tp

saveit, ax = tp.tee(  # create a callback object to finalize plot
    sns.boxplot,  # plotter...
    sns.load_dataset("planets"),  # ...forwarded arg & kwargs
    x="distance", y="method", hue="method", palette="vlag",
    whis=[0, 100], width=.6,  # ... and then teeplot options
    teeplot_callback=True, teeplot_postprocess="teed.set_xscale('log')")
ax.xaxis.grid(True)  # now some tweaks
plt.gcf().set_size_inches(10, 4)
saveit()  # dispatch output callback

Example 3

Example with matplotlib, also showing use of teeplot_callback kwarg .

# adapted from
from matplotlib import pyplot as plt
import numpy as np; from teeplot import teeplot as tp

data = {'a': np.arange(50), 'c': np.random.randint(0, 50, 50),
        'd': np.random.randn(50)}
data['b'], data['d'] = data['a'] + 10 * np.random.randn(50), np.abs(data['d']) * 100

saveit, __ = tp.tee(  # create a callback object to finalize plot
    plt.scatter,  # plotter...
    data=data, x='a', y='b', c='c', s='d',  # ...forwarded kwargs
    teeplot_callback=True)  # teeplot options
plt.xlabel('entry a')  # now some tweaks
plt.ylabel('entry b')
plt.gcf().set_size_inches(5, 3)
saveit()  # dispatch output callback

Example 4

Example with seaborn FacetGrid demonstrating use of exec’ed teeplot_postprocess that adds a map_dataframe step over the teed result value and also results in additional semantic information being added to plot filenames (under the “post=” key).

# adapted from
import seaborn as sns
from teeplot import teeplot as tp

    sns.FacetGrid,  # plotter...
    sns.load_dataset("tips"),  # ...forwarded args & kwwargs
    col="time", hue="sex", aspect=1.5,
    teeplot_postprocess="teed.map_dataframe(sns.scatterplot, x='total_bill', y='tip')")

Example 5

Demonstration of teeplot use with a custom function. Note the function name automatically used as “viz=” key in output filenames.

# adapted from
import seaborn as sns; from teeplot import teeplot as tp
df = sns.load_dataset("car_crashes")

def dot_plot(data, x_vars, y_vars):  # custom plotter
    g = sns.PairGrid(data.sort_values("total", ascending=False),
                    x_vars=x_vars, y_vars=y_vars,
                    height=5, aspect=0.66), size=10, orient="h", jitter=False,
        palette="flare_r", linewidth=1, edgecolor="w")
    for ax in g.axes.flat:

    dot_plot,  # plotter, then forwarded args/kwargs
    df[df["abbrev"].str.contains("A")], x_vars=df.columns[:-3], y_vars=["abbrev"],
    teeplot_outinclude=["x_vars", "y_vars"], teeplot_save={".eps", ".png"})



Executes a plotting function and saves the resulting plot to specified formats using a descriptive filename automatically generated from plotting function arguments.




The plotting function to be executed. Required.

Additional args & kwargs

Forwarded to the plotting function and used to build the output filename.


If True, returns a tuple with a callback to dispatch plot save instead of immediately saving the plot after running the plotter. Default is False.


Resolution for rasterized components of saved plots, default is publication-quality 300 dpi.


Strategy for handling filename collisions: “error”, “fix”, “ignore”, or “warn”, default “warn”; inferred from environment if not specified.


Dict with additional key-value attributes to include in the output filename.


Base directory for saving plots, default “teeplots”.


Attribute keys to always include, if present, in the output filename.


Attribute keys to always exclude, if present, from the output filename.


Actions to perform after plotting but before saving. Can be a string of code to exec or a callable function. If a string, it’s executed with access to plt and sns (if installed), and the plotter return value as teed.


File formats to save the plots in. Defaults to global settings if True, all output suppressed if False. Default global setting is {" .png", ".pdf"}. Supported: “.eps”, “.png”, “.pdf”, “.ps”, “.svg”.


Dictates whether should be called after plot is saved. If True, the plot is displayed using Default behavior is to display if an interactive environment is detected (e.g., a notebook).


Optionally, subdirectory within the main output directory for plot organization.


Option to save the plot with a transparent background, default True.


Toggles printing of saved filenames, default True.

Return Value: returned result from plotter call if teeplot_callback is False, otherwise tuple of save-plot callback and result from plotter call.

Module-Level Configuration

  • teeplot.draftmode: A boolean indicating whether to suppress output to all file formats.

  • teeplot.oncollision: Default strategy for handling filename collisions, with options like ‘error’, ‘fix’, ‘ignore’, or ‘warn’.

  • A dictionary mapping file formats (e.g., “.png”) to default save behavior as True (always output), False (never output), or None (defer to call kwargs).

Environment Variables

  • TEEPLOT_ONCOLLISION: Configures the default collision handling strategy. See teeplot_oncollision kwarg

  • TEEPLOT_DRAFTMODE: If set, enables draft mode globally.

  • TEEPLOT_<FORMAT>: Boolean flags that determine default behavior for each format (e.g., EPS, PNG, PDF, PS, SVG); “defer” defers to call kwargs.

  • CI, etc.: If a continuous integration environment is detected, default teeplot_save behavior will output only .pdf files, instead of .pdf and .png files. This can be overridden with TEEPLOT_<FORMAT>.


Output filenames are constructed using the keyname package.

This package was created with Cookiecutter and the audreyr/cookiecutter-pypackage project template.

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

teeplot-1.0.1.tar.gz (1.5 MB view hashes)

Uploaded source

Built Distribution

teeplot-1.0.1-py2.py3-none-any.whl (11.1 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page