Plotting onto Column Cells#

By providing a plot_fn (Callable) to a ColumnDefinition, plottable creates an axes on top of each Cell of this column, and creates plots based on each cell’s value.

You can provide additional keywords to the plot function by passing a plot_kw dictionary to ColumnDefinition.


    plot_fn: Callable = None
        A Callable that will take the cells value as input and create a subplot
        on top of each cell and plot onto them.
        To pass additional arguments to it, use plot_kw (see below).
    plot_kw: Dict[str, Any] = field(default_factory=dict)
        Additional keywords provided to plot_fn.

Commonly used example plots are provided in plottable.plots. You can have a look at them below.

Creating Custom Plot Functions#

You can also easily create your own functions. Just make sure to have
ax: matplotlib.axes.Axes as first and
val: Any (the cells value) as second arguments.

def custom_plot_fn(
    ax: matplotlib.axes.Axes,
    val: Any,
    # further arguments that can be passed via plot_kw
    ):
    ...

for more complex data you can create a dictionary or function that gets data based on the cells value, ie.

def custom_plot_fn(
    ax: matplotlib.axes.Axes,
    val: Any,
    # further arguments that can be passed via plot_kw
    ):
    
    data = my_data_dict.get(val)
    or
    data = my_data_getter_function(val)

You can create Sparklines, Histograms, … you name it.

If you create any cool plots to use with plottable, please consider sharing them by creating a Pull Request!

Available Plots#

%load_ext autoreload
%autoreload 2

from pathlib import Path

import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
from matplotlib.colors import LinearSegmentedColormap

from plottable import ColumnDefinition, Table
from plottable.plots import *
path = list(Path("../example_notebooks/country_flags").glob("*.png"))[0]
cmap = LinearSegmentedColormap.from_list(
    name="bugw", colors=["#ffffff", "#f2fbd2", "#c9ecb4", "#93d3ab", "#35b0ab"], N=256
)

percentile_bars#

fig, ax = plt.subplots(figsize=(1, 0.5))

bars = percentile_bars(ax=ax, val=72, color="#b0db7c", background_color="#f0f0f0", is_pct=False)

plt.show()

# fig.savefig(Path.home() / "Downloads/percentile_plot.png")
../_images/dc3fe1b4a0889469ae20e6932c9475377d37788062cc4ec2a9451aa5c5d96df2.png

image#

fig, ax = plt.subplots(figsize=(1, 1))

image(ax, path)

plt.show()
../_images/8e1ee0417cb02772f45e7169a2291a8ec15f08fc600684315178e550b7d4ff3c.png

circled_image#

fig, ax = plt.subplots(figsize=(1, 1))

im = circled_image(ax, path)

plt.show()
../_images/a1a2aa7317093f1edb22c81325c27bc961c1de860bb0fcfe3c74ad65a323aca6.png

circled_image with border#

fig, ax = plt.subplots(figsize=(1, 1))

im = circled_image(ax, path, linewidth=2, visible=True, edgecolor="#999999")

plt.show()
../_images/4b788f2d889da3a29ec84c337eb332264442e4a4c0dc575fae53a4bf043138d7.png

bar#

fig, ax = plt.subplots(figsize=(1, 1))
b = bar(ax, 1, color="k", cmap=cmap)
plt.show()
../_images/a6578ee3b900ba5bb01ca3f0d2d8c511f63ebb235f8776684e9636ee98eeeb7f.png

bar with value annotation and linecolor#

fig, ax = plt.subplots(figsize=(1, 1))
b = bar(ax, 0.5, plot_bg_bar=True, cmap=cmap, annotate=True, lw=1, height=0.35)
plt.show()
../_images/1824cc4baad07aad8e449f93ae661ee832594712c55e210247e90ac3b5d9bf2c.png

percentile_stars#

fig, ax = plt.subplots(figsize=(2, 1))

stars = percentile_stars(ax, 70, background_color="#f0f0f0")
../_images/16d65bce6854de8bb8f87816c8814e862e9f4c783b7a7f51471789d667c4573d.png

progress_donut#

fig, ax = plt.subplots(figsize=(1, 1))
donut = progress_donut(ax, 73, textprops={"fontsize": 14})
plt.show()
../_images/75c5dd2365b34e9785ae985424b9ad12cef20de985f416a15c9677af58dbc62b.png