Matplotlib & Seaborn Accessible Plot Examples

Code examples showing how to make matplotlib and seaborn bar plots, histograms, line charts, box plots, heatmaps, scatter plots, and more accessible with py-maidr.

Matplotlib / Seaborn Examples

Making accessible data representation with maidr is easy and straightforward. If you already have data visualization code using matplotlib or seaborn, you can make your plots accessible with maidr in just a few lines of code. For Plotly examples, see the Plotly Examples page.

Simply import maidr and call plt.show() as usual. maidr automatically activates a custom matplotlib backend, so plt.show() renders accessible HTML output (with sonification, braille, and tactile support) instead of a static image.

Custom Backend

When you import maidr, a custom matplotlib backend is automatically activated. This means plt.show() renders accessible HTML output instead of a static image.

Switching Back to the Default Renderer

If you want to temporarily use the default matplotlib renderer (e.g. for unsupported plot types or debugging), you can switch the backend:

In Jupyter notebooks:

maidr.set_backend(use_maidr=False)   # plt.show() now renders static inline images
maidr.set_backend(use_maidr=True)    # plt.show() renders accessible maidr output again

In Python scripts (non-notebook):

maidr.set_backend(use_maidr=False)   # plt.show() now opens the native image viewer (e.g. macOS, TkAgg)
maidr.set_backend(use_maidr=True)    # plt.show() renders accessible maidr output again
Note

maidr.show() always renders accessible output regardless of the active backend. You only need maidr.set_backend() to control the behavior of plt.show().

Unsupported Plot Types

For plot types not yet supported by maidr (e.g. pie charts, contour plots, 3D plots), plt.show() will automatically fall back to displaying a static image and emit a warning. No code changes are needed — your plots will always be visible.

Bar Plots

Simple Bar Plot

import matplotlib.pyplot as plt
import seaborn as sns

# Just import maidr package 
import maidr  


# Load the penguins dataset
penguins = sns.load_dataset("penguins")

# Create a bar plot showing the average body mass of penguins by species
fig, ax = plt.subplots(figsize=(6, 6))

# Assign the plot to a variable
bar_plot = sns.barplot(
    x="species", y="body_mass_g", data=penguins, errorbar="sd", palette="Blues_d", ax=ax
)
ax.set_title("Average Body Mass of Penguins by Species")
ax.set_xlabel("Species")
ax.set_ylabel("Body Mass (g)")

# Add number formatter for better screen reader output
ax.yaxis.set_major_formatter("{x:,.0f}")

# plt.show() now renders accessible maidr output 
plt.show()