Skip to main content

Maxlotlib

Maxplotlib

A clean, expressive wrapper around Matplotlib, Plotly, plotext, and tikzfigure for producing publication-quality figures with minimal boilerplate. Swap backends without rewriting your data — render the same canvas as a crisp PNG, an interactive Plotly chart, a terminal-native plotext figure, or camera-ready TikZ code for LaTeX.

Install

pip install maxplotlibx

Showcase

Quickstart

import numpy as np
from maxplotlib import Canvas

x = np.linspace(0, 2 * np.pi, 200)
y = np.sin(x)

canvas, ax = Canvas.subplots()
ax.plot(x, y)

Figure 1

Plot the figure with the default (matplotlib) backend:

canvas.show()

For Matplotlib-specific customization, pass method calls declaratively. Figure methods run once and axes methods run for every subplot, providing access to any Matplotlib API without requiring a maxplotlib wrapper:

canvas.plot(matplotlib_customizations={
    "figure": {
        "suptitle": "My figure",
    },
    "axes": {
        "tick_params": {
            "axis": "both",
            "which": "major",
            "length": 6,
        },
    },
})

For dynamic customization, the same option also accepts a function:

def customize(fig, axes):
    fig.suptitle("My figure")
    for ax in axes.flat:
        ax.tick_params(axis="both", which="major", length=6)

canvas.plot(matplotlib_customizations=customize)

Axis Label and Tick Styling

Axis labels, titles, and tick appearance accept Matplotlib-style keyword arguments:

canvas.set_xlabel("Time", fontsize=12, fontweight="bold", labelpad=10)
canvas.set_ylabel("Duration", color="darkblue")
canvas.set_title("Runtime", fontsize=14, color="navy")
canvas.tick_params(
    axis="both",
    which="major",
    labelsize=10,
    colors="darkgreen",
    length=6,
)

Common axis controls and figure-level layout settings are also available:

canvas.set_facecolor("whitesmoke")
canvas.set_axisbelow(True)
canvas.margins(x=0.05, y=0.1)
canvas.minorticks_on()
canvas.invert_yaxis()
canvas.supxlabel("Shared x label")
canvas.supylabel("Shared y label")
canvas.subplots_adjust(left=0.15, bottom=0.15)
canvas.tight_layout()

Secondary Y-Axis

Use Canvas.twinx() to add a second y-axis that shares the primary x-axis:

twin_canvas, primary = Canvas.subplots()
secondary = twin_canvas.twinx()

primary.plot(x, np.sin(x), color="tab:blue")
secondary.plot(x, 100 * np.cos(x), color="tab:red")
primary.set_ylabel("sin(x)", color="tab:blue")
secondary.set_ylabel("100 cos(x)", color="tab:red")

twin_canvas.show()

Secondary y-axes are currently supported by the Matplotlib and Plotly backends.

Plotly field plots and tables

Several Matplotlib field and annotation APIs map directly to interactive Plotly traces, including pseudocolor plots, sparsity patterns, triangular grids, and tables:

plotly_canvas, plotly_ax = Canvas.subplots()
plotly_ax.pcolor(x, x, np.outer(np.sin(x), np.cos(x)))
plotly_ax.spy([[1, 0, 1], [0, 1, 0], [1, 0, 1]])
plotly_ax.table(cellText=[["A", "B"], ["1", "2"]])
plotly_canvas.show(backend="plotly")

Plotly raises NotImplementedError for primitives without a faithful equivalent instead of silently dropping them. To render the supported parts of a mixed canvas, explicitly opt into skipping unsupported primitives:

plotly_canvas.plot(backend="plotly", allow_unsupported=True)

Render the same line graph directly in the terminal with the plotext backend:

terminal_fig = canvas.plot(backend="plotext")
print(terminal_fig.build(keep_colors=False))
                                       Runtime                                  
     ┌─────────────────────────────────────────────────────────────────────────┐
 1.00┤             ▗▄▞▀▀▀▀▀▙▄▖                                                 │
     │          ▗▄▀▘         ▝▀▄                                               │
     │        ▗▞▘               ▀▄                                             │
 0.67┤       ▟▀                   ▀▄                                           │
     │     ▄▛                       ▚▖                                         │
 0.33┤   ▗▞                          ▝▄                                        │
     │  ▄▀                             ▚▖                                      │
     │▗▞▘                               ▀▄                                     │
 0.00┤▀                                  ▝▚▖                                  ▞│
     │                                     ▀▄                               ▗▞▘│
     │                                      ▝▚                             ▄▀  │
-0.33┤                                        ▀▖                          ▞▘   │
     │                                         ▝▚                       ▟▀     │
-0.67┤                                           ▀▄                   ▄▛       │
     │                                             ▀▄               ▗▞▘        │
     │                                               ▀▄▖         ▗▄▀▘          │
-1.00┤                                                 ▝▀▜▄▄▄▄▄▞▀▘             │
     └┬─────────────────┬─────────────────┬─────────────────┬─────────────────┬┘
     0.0               1.6               3.1               4.7              6.3 
Duration                                Time                                    

Or plot with the TikZ backend:

canvas.show(backend="tikzfigure")

Horizontal Subplots with TikZ Backend

The tikzfigure backend supports creating side-by-side subplots (1×n layouts):

x = np.linspace(0, 2 * np.pi, 200)
canvas, (ax1, ax2) = Canvas.subplots(ncols=2, width="10cm", ratio=0.3)

ax1.plot(x, np.sin(x), color="royalblue")
ax1.set_title("sin(x)")

ax2.plot(x, np.cos(x), color="tomato")
ax2.set_title("cos(x)")

canvas.suptitle("Trigonometric Functions")
canvas.show(backend="tikzfigure")  # Generates LaTeX subfigures

Figure 2

Note: Only horizontal layouts (1×n) are currently supported with the tikzfigure backend. Vertical/grid layouts will raise NotImplementedError. See the tutorials for more examples.

Terminal Backend with plotext

The plotext backend is designed for terminal-first workflows. It currently supports line plots, scatter plots, bars, filled regions, error bars, reference lines, text/annotations, labels/titles, log axes, layers, matrix-style imshow() rendering, common patches, and multi-subplot canvases.

x = np.linspace(1, 10, 40)

canvas, ax = Canvas.subplots()
ax.plot(x, np.sqrt(x), color="cyan", label="sqrt(x)")
ax.errorbar(x[::8], np.sqrt(x[::8]), yerr=0.15, color="yellow", label="samples")
ax.set_title("Terminal plot")
ax.set_xlabel("x")
ax.set_ylabel("y")
ax.set_xscale("log")
ax.set_legend(True)

canvas.show(backend="plotext")
                                    Terminal plot                               
    ┌──────────────────────────────────────────────────────────────────────────┐
3.16┤ ▞▞ sqrt(x)                                                             ▄▞│
    │                                                                   │▗▄▞▀  │
    │                                                                  ▄┼▘     │
2.79┤                                                               ▄▀▀        │
    │                                                            ┼▀▀           │
2.42┤                                                        ▗▞▀▀│             │
    │                                                    ▗▞▀▀▘                 │
    │                                               ▗▄┼▄▀▘                     │
2.04┤                                            ▗▄▀▘ │                        │
    │                                        ▗▄▞▀▘                             │
    │                                 │  ▄▄▀▀▘                                 │
1.67┤                              ▗▄▄┼▀▀                                      │
    │                        ▗▄▄▞▀▀▘                                           │
1.30┤                 ▄▄▄▄▀▀▀▘                                                 │
    │            ▄▄▞▀▀                                                         │
    │┼  ▗▄▄▞▀▀▀▀▀                                                              │
0.93┤│▀▀▘                                                                      │
    └┬─────────────────┬──────────────────┬─────────────────┬─────────────────┬┘
    1.0               1.8                3.2               5.6             10.0 
y                                         x                                     

<maxplotlib.backends.plotext.figure.PlotextFigure at 0x110a30550>

Layers

x = np.linspace(0, 2 * np.pi, 200)

canvas, ax = Canvas.subplots(width="10cm", ratio=0.55)

ax.plot(x, np.sin(x), color="steelblue", label=r"$\sin(x)$", layer=0)
ax.plot(x, np.cos(x), color="tomato", label=r"$\cos(x)$", layer=1)
ax.plot(
    x,
    np.sin(x) * np.cos(x),
    color="seagreen",
    label=r"$\sin(x)\cos(x)$",
    linestyle="dashed",
    layer=2,
)

ax.set_xlabel("x")
ax.set_legend(True)

Figure 3

Show layer 0 only, then layers 0 and 1, then everything:

canvas.show(layers=[0])

(<Figure size 590.551x324.803 with 1 Axes>,
 array([[<Axes: xlabel='x'>]], dtype=object))

Show all layers:

canvas.show()

(<Figure size 590.551x324.803 with 1 Axes>,
 array([[<Axes: xlabel='x'>]], dtype=object))

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

maxplotlibx-0.1.7.tar.gz (60.7 kB view details)

Uploaded Source

Built Distribution

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

maxplotlibx-0.1.7-py3-none-any.whl (63.1 kB view details)

Uploaded Python 3

File details

Details for the file maxplotlibx-0.1.7.tar.gz.

File metadata

  • Download URL: maxplotlibx-0.1.7.tar.gz
  • Upload date:
  • Size: 60.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.21

File hashes

Hashes for maxplotlibx-0.1.7.tar.gz
Algorithm Hash digest
SHA256 4a791d838dfa1fc1df3af370912ea9298c939f1d757fa00f514ec8b88c7a8b09
MD5 d68e8f0bd48e43b48ee86a35e4a1abd5
BLAKE2b-256 7e1e0081f19ca948581343738451226da962d94e086e102ec01f3679e628d00e

See more details on using hashes here.

File details

Details for the file maxplotlibx-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: maxplotlibx-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 63.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.10.21

File hashes

Hashes for maxplotlibx-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 fa2d9dcfe10ce20d4547aa72a48cd7f7cabfe60754cff041ecbd266137704366
MD5 b2fa0575a8368fc1c62dd57e73ac12c6
BLAKE2b-256 a5c56606703057d8bd1774309bd296d167b898aa112ff1188a89d42c05af9745

See more details on using hashes here.

Release history Release notifications | RSS feed

0.1.9

2 files

0.1.8

2 files

This release

0.1.7 This release

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page