Textual Plotext

raw JSON →
1.0.1 verified Mon Apr 27 auth: no python

A Textual widget wrapper for the Plotext plotting library, enabling interactive terminal-based plots within Textual applications. Current version: 1.0.1. Active development.

pip install textual-plotext
error AttributeError: module 'plotext' has no attribute 'plt'
cause PlotextPlot.plt is an instance of plotext.plot.Plot, not the module.
fix
Access plt via the widget instance: plot.plt
error TypeError: 'PlotextPlot' object does not support indexing
cause Trying to use PlotextPlot as a container or callable directly.
fix
Use PlotextPlot as a widget: app.compose() yield PlotextPlot()
gotcha Calling plt.clf() resets the plot size to a default, causing layout flicker. Use plot.clear() instead to reset data while preserving size.
fix Use the widget's clear() method instead of plotext.clf()
gotcha PlotextPlot uses a fixed canvas size; setting widget height/width in CSS may not affect the plot's internal resolution, causing clipping.
fix Adjust the plot via plt.subplots(height, width) or use proportional sizing in the Plotext plot object.
deprecated Themes prefixed 'textual-' are experimental; future versions may rename them.
fix Use the builtin plotext themes without prefix, or customize colors.

Create a simple Textual app with a scatter plot.

import asyncio
from textual.app import App, ComposeResult
from textual_plotext import PlotextPlot

class PlotApp(App):
    def compose(self) -> ComposeResult:
        yield PlotextPlot(id="plot")

    def on_mount(self) -> None:
        plot = self.query_one("#plot", PlotextPlot)
        plt = plot.plt
        plt.title("Quickstart Plot")
        plt.scatter([1, 2, 3], [4, 5, 6])
        plt.plot([1, 2, 3], [4, 5, 6])
        plot.refresh()

if __name__ == "__main__":
    app = PlotApp()
    asyncio.run(app.run_async())