Style Matplotlib Plots#

This guide addresses how to style Matplotlib plots displayed using the Matplotlib pane.

There are nearly 30 builtin styles to Matplotlib that can be activated with the function. The style names are listed in the array.

For more info check out the Matplotlib style sheets reference and the alternative themes dracula theme and gadfly.

The gif below displays an example of what can be achieved with a little styling of the Matplotlib figure and the FastListTemplate.

Matplotlib + FastListTemlate Styling Example

A Matplotlib plot with custom style and accent color#

In this example we will give the Matplotlib plot a custom style and accent color.

import numpy as np

from matplotlib.figure import Figure
import matplotlib.pyplot as plt
import panel as pn


def plot(style, color):
    x = np.arange(-2, 8, 0.1)
    y = 0.1 * x**3 - x**2 + 3 * x + 2"default")  # reset to not be affected by previous style changes  # change to the specified style

    fig0 = Figure(figsize=(12, 6))
    ax0 = fig0.subplots()
    ax0.plot(x, y, linewidth=10.0, color=color)
    ax0.set_title(f"Matplotlib Style: {style}")"default")  # reset to not affect style of other plots

    return fig0

styles = sorted(
style = pn.widgets.Select(value="dark_background", options=styles, name="Style")
color = pn.widgets.ColorPicker(value="#F08080", name="Color")

    pn.Row(style, color),
        pn.bind(plot, style=style, color=color),
    "**Matplotlib Styles**: " + ", ".join(styles),