Skip to content

Plot

Overview

Plot provides a convenient way to render Matplotlib figures as an image.

Examples

from matplotlib.figure import Figure

import mesop as me


@me.page(
  security_policy=me.SecurityPolicy(
    allowed_iframe_parents=["https://google.github.io"]
  ),
  path="/plot",
)
def app():
  # Create matplotlib figure without using pyplot:
  fig = Figure()
  ax = fig.subplots()  # type: ignore
  ax.plot([1, 2])  # type: ignore

  me.text("Example using matplotlib:")
  me.plot(fig, style=me.Style(width="100%"))

API

plot

Creates a plot component from a Matplotlib figure.

PARAMETER DESCRIPTION
figure

A Matplotlib figure which will be rendered.

TYPE: Figure

style

An optional Style object that defines the visual styling for the plot component. If None, default styling (e.g. height, width) is used.

TYPE: Style | None DEFAULT: None