The Pyplot class allows you to display a Matplotlib pyplot chart in the chatbot UI. This class takes a pyplot figure.

The difference of between this element and the Plotly element is that the user is shown a static image of the chart when using Pyplot.

Attributes

name
str

The name of the chart to be displayed in the UI.

display
ElementDisplay

Determines how the chart element should be displayed in the UI. Choices are “side” (default), “inline”, or “page”.

size
ElementSize

Determines the size of the chart. Only works with display=“inline”. Choices are “small”, “medium” (default), or “large”.

figure
str

The matplotlib.figure.Figure instance that you want to display.

Example

import matplotlib.pyplot as plt
import chainlit as cl


@cl.on_chat_start
async def main():
    fig, ax = plt.subplots()
    ax.plot([1, 2, 3, 4], [1, 4, 2, 3])

    elements = [
        cl.Pyplot(name="plot", figure=fig, display="inline"),
    ]
    await cl.Message(
        content="Here is a simple plot",
        elements=elements,
    ).send()