Claude Code for plotext: Terminal Charts and Plots in Python — Claude Skills 360 Blog
Blog / AI / Claude Code for plotext: Terminal Charts and Plots in Python
AI

Claude Code for plotext: Terminal Charts and Plots in Python

Published: March 27, 2028
Read time: 5 min read
By: Claude Skills 360

plotext renders scatter, line, bar, and histogram charts directly in the terminal with optional color themes. pip install plotext. Line: import plotext as plt; plt.plot([1,2,3,4]); plt.title("Line"); plt.show(). Scatter: plt.scatter(x, y). Bar: plt.bar(["A","B","C"],[10,20,15]); plt.show(). Simple bar H: plt.simple_bar(labels, values). Histogram: plt.hist(data, bins=20). Multiple series: plt.plot(y1, label="A"); plt.plot(y2, label="B"). XY: plt.scatter(x_data, y_data). Axes labels: plt.xlabel("Time"); plt.ylabel("Value"). Limits: plt.xlim(0, 100); plt.ylim(-1, 1). Grid: plt.grid(True). Theme: plt.theme("dark") — also “clear”, “pro”, “matrix”, “dreamland”, “grandpa”, “salad”, “elegant”, “girly”. Date: plt.date_form("Y-m-d") then plt.plot(dates, values). Subplots: plt.subplots(2, 2); plt.subplot(1, 1); plt.plot(...). plt.plotsize(100, 30) — set width/height in characters. plt.canvas_color("black"). plt.axes_color("black"). plt.ticks_color("white"). Build (no show): plt.build() → returns string. plt.clear_figure(). Image: plt.image_plot("img.png"); plt.show(). Frame: plt.frame(True). Save: plt.save_fig("chart.txt"). Horizontal bar: plt.bar(labels, values, orientation="h"). Stacked bar: plt.stacked_bar(labels, matrix_of_values). Get: plt.terminal_size() for width/height. Claude Code generates plotext charts, dashboards, and real-time metric visualizations.

CLAUDE.md for plotext

## plotext Stack
- Version: plotext >= 5.3 | pip install plotext
- Line: plt.plot(y) | plt.plot(x, y) | plt.show()
- Scatter: plt.scatter(x, y, marker="braille") — braille for high-res dots
- Bar: plt.bar(labels, values) | plt.bar(labels, values, orientation="h")
- Hist: plt.hist(data, bins=20, label="dist") — distribution view
- Themes: plt.theme("dark") | "pro" | "matrix" | "clear" | "elegant"
- Build: plt.build() → str for embedding; plt.clear_figure() to reset

plotext Terminal Chart Pipeline

# app/charts.py — plotext line, scatter, bar, histogram, and subplot dashboards
from __future__ import annotations

import math
import time
from collections import deque
from typing import Any

import plotext as plt


# ─────────────────────────────────────────────────────────────────────────────
# 1. Basic chart helpers
# ─────────────────────────────────────────────────────────────────────────────

def line_chart(
    y: list[float],
    x: list[float] | None = None,
    title: str = "",
    xlabel: str = "",
    ylabel: str = "",
    label: str = "",
    color: str = "blue",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """Render a single-series line chart and return as string."""
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    if xlabel:
        plt.xlabel(xlabel)
    if ylabel:
        plt.ylabel(ylabel)
    if x is not None:
        plt.plot(x, y, label=label, color=color)
    else:
        plt.plot(y, label=label, color=color)
    return plt.build()


def scatter_chart(
    x: list[float],
    y: list[float],
    title: str = "",
    xlabel: str = "",
    ylabel: str = "",
    label: str = "",
    marker: str = "braille",
    color: str = "green",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """Render a scatter chart and return as string."""
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    if xlabel:
        plt.xlabel(xlabel)
    if ylabel:
        plt.ylabel(ylabel)
    plt.scatter(x, y, label=label, marker=marker, color=color)
    return plt.build()


def multi_line_chart(
    series: dict[str, list[float]],
    x: list[float] | None = None,
    title: str = "",
    xlabel: str = "",
    ylabel: str = "",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """
    Render multiple named series on one chart.
    series: {"label": [values], ...}
    """
    colors = ["blue", "red", "green", "yellow", "magenta", "cyan"]
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    if xlabel:
        plt.xlabel(xlabel)
    if ylabel:
        plt.ylabel(ylabel)
    for (label, values), color in zip(series.items(), colors):
        if x is not None:
            plt.plot(x, values, label=label, color=color)
        else:
            plt.plot(values, label=label, color=color)
    return plt.build()


# ─────────────────────────────────────────────────────────────────────────────
# 2. Bar charts
# ─────────────────────────────────────────────────────────────────────────────

def bar_chart(
    labels: list[str],
    values: list[float],
    title: str = "",
    horizontal: bool = False,
    color: str = "blue",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """Vertical or horizontal bar chart."""
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    orientation = "h" if horizontal else "v"
    plt.bar(labels, values, color=color, orientation=orientation)
    return plt.build()


def stacked_bar_chart(
    labels: list[str],
    series: dict[str, list[float]],
    title: str = "",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """
    Stacked bar chart.
    series: {"group_label": [value_per_bar], ...}
    """
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    matrix = list(series.values())
    series_labels = list(series.keys())
    plt.stacked_bar(labels, matrix, labels=series_labels)
    return plt.build()


# ─────────────────────────────────────────────────────────────────────────────
# 3. Histogram
# ─────────────────────────────────────────────────────────────────────────────

def histogram(
    data: list[float],
    bins: int = 20,
    title: str = "",
    label: str = "Distribution",
    color: str = "cyan",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """Frequency histogram."""
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    plt.hist(data, bins=bins, label=label, color=color)
    return plt.build()


def multi_histogram(
    datasets: dict[str, list[float]],
    bins: int = 20,
    title: str = "",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """Multiple overlaid histograms."""
    colors = ["blue", "red", "green", "yellow"]
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    if title:
        plt.title(title)
    for (label, data), color in zip(datasets.items(), colors):
        plt.hist(data, bins=bins, label=label, color=color)
    return plt.build()


# ─────────────────────────────────────────────────────────────────────────────
# 4. Subplots / grid dashboard
# ─────────────────────────────────────────────────────────────────────────────

def grid_dashboard(
    panels: list[dict[str, Any]],
    rows: int = 2,
    cols: int = 2,
    theme: str = "dark",
    width: int = 120,
    height: int = 40,
) -> str:
    """
    Render multiple charts in a grid layout.

    panels: list of chart config dicts, one per cell:
        {"type": "line"|"bar"|"scatter"|"hist",
         "title": ..., "y": [...], "x": [...],
         "labels": [...], "values": [...], "data": [...]}
    """
    plt.clear_figure()
    plt.plotsize(width, height)
    plt.theme(theme)
    plt.subplots(rows, cols)

    for i, panel in enumerate(panels[:rows * cols]):
        r = i // cols + 1
        c = i % cols + 1
        plt.subplot(r, c)
        chart_type = panel.get("type", "line")

        if panel.get("title"):
            plt.title(panel["title"])

        if chart_type == "line":
            if "x" in panel:
                plt.plot(panel["x"], panel["y"], color=panel.get("color", "blue"))
            else:
                plt.plot(panel.get("y", []), color=panel.get("color", "blue"))
        elif chart_type == "scatter":
            plt.scatter(panel.get("x", []), panel.get("y", []),
                        marker=panel.get("marker", "dot"))
        elif chart_type == "bar":
            plt.bar(panel["labels"], panel["values"],
                    color=panel.get("color", "blue"))
        elif chart_type == "hist":
            plt.hist(panel.get("data", []), bins=panel.get("bins", 10))

    return plt.build()


# ─────────────────────────────────────────────────────────────────────────────
# 5. Scrolling / live chart
# ─────────────────────────────────────────────────────────────────────────────

class LiveChart:
    """
    Scrolling line chart backed by a deque — update and re-render each tick.

    Usage:
        chart = LiveChart(width=70, title="Requests/s")
        while True:
            chart.push(rps())
            chart.display()
            time.sleep(1)
    """

    def __init__(
        self,
        maxlen: int = 60,
        width: int = 80,
        height: int = 15,
        title: str = "Live",
        ylabel: str = "",
        color: str = "green",
        theme: str = "dark",
        ymin: float | None = None,
        ymax: float | None = None,
    ):
        self._buf: deque[float] = deque([0.0] * maxlen, maxlen=maxlen)
        self._width = width
        self._height = height
        self._title = title
        self._ylabel = ylabel
        self._color = color
        self._theme = theme
        self._ymin = ymin
        self._ymax = ymax

    def push(self, value: float) -> None:
        self._buf.append(value)

    def render(self) -> str:
        data = list(self._buf)
        plt.clear_figure()
        plt.plotsize(self._width, self._height)
        plt.theme(self._theme)
        plt.title(self._title)
        if self._ylabel:
            plt.ylabel(self._ylabel)
        if self._ymin is not None:
            plt.ylim(self._ymin, self._ymax or max(data) or 1)
        plt.plot(data, color=self._color)
        return plt.build()

    def display(self) -> None:
        import os
        os.system("clear")
        print(self.render())


# ─────────────────────────────────────────────────────────────────────────────
# 6. pandas / numpy integration
# ─────────────────────────────────────────────────────────────────────────────

def from_series(
    series,
    title: str = "",
    color: str = "blue",
    chart_type: str = "line",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """
    Plot a pandas Series or numpy array.
    chart_type: "line" | "scatter" | "bar" | "hist"
    """
    import numpy as np
    y = list(series)
    x = list(range(len(y)))

    if chart_type == "hist":
        return histogram(y, title=title, color=color, theme=theme, width=width, height=height)
    elif chart_type == "bar":
        labels = [str(i) for i in range(len(y))]
        return bar_chart(labels, y, title=title, color=color, theme=theme, width=width, height=height)
    elif chart_type == "scatter":
        return scatter_chart(x, y, title=title, color=color, theme=theme, width=width, height=height)
    else:
        return line_chart(y, title=title, color=color, theme=theme, width=width, height=height)


def from_dataframe(
    df,
    columns: list[str],
    title: str = "",
    theme: str = "dark",
    width: int = 80,
    height: int = 20,
) -> str:
    """Plot selected columns of a pandas DataFrame as multi-line chart."""
    series = {col: list(df[col]) for col in columns}
    return multi_line_chart(series, title=title, theme=theme, width=width, height=height)


# ─────────────────────────────────────────────────────────────────────────────
# Demo
# ─────────────────────────────────────────────────────────────────────────────

if __name__ == "__main__":
    import random

    print("=== Line chart (sine) ===")
    x_vals = [i * 0.1 for i in range(100)]
    y_vals = [math.sin(x) for x in x_vals]
    print(line_chart(y_vals, title="Sine Wave", ylabel="sin(x)", color="blue"))

    print("\n=== Scatter chart ===")
    xs = [random.gauss(0, 1) for _ in range(200)]
    ys = [random.gauss(0, 1) for _ in range(200)]
    print(scatter_chart(xs, ys, title="Random Scatter", marker="braille"))

    print("\n=== Multi-line chart ===")
    series = {
        "sin":  [math.sin(i * 0.1) for i in range(80)],
        "cos":  [math.cos(i * 0.1) for i in range(80)],
        "tan÷5":[math.tan(i * 0.1) / 5 for i in range(80)],
    }
    print(multi_line_chart(series, title="Trig Functions", ylabel="value"))

    print("\n=== Bar chart ===")
    print(bar_chart(
        ["Jan", "Feb", "Mar", "Apr", "May", "Jun"],
        [12500, 14200, 16800, 15100, 18300, 21000],
        title="Monthly Revenue ($)",
        color="green",
    ))

    print("\n=== Histogram ===")
    data = [random.gauss(50, 10) for _ in range(500)]
    print(histogram(data, bins=20, title="Normal Distribution (μ=50, σ=10)"))

    print("\n=== Grid dashboard (2×2) ===")
    panels = [
        {"type": "line",    "title": "CPU %",   "y": [random.uniform(20,80) for _ in range(60)], "color": "green"},
        {"type": "bar",     "title": "Traffic",  "labels": ["US","EU","APAC","Other"], "values": [45,30,20,5], "color": "blue"},
        {"type": "hist",    "title": "Latency",  "data": [random.expovariate(0.1) for _ in range(200)], "bins": 15},
        {"type": "scatter", "title": "Error Rate","x": list(range(50)), "y": [random.uniform(0,5) for _ in range(50)]},
    ]
    print(grid_dashboard(panels, rows=2, cols=2, width=120, height=40))

For the asciichartpy alternative — asciichartpy is a minimal single-file library ideal for pure line charts with no external dependencies; plotext supports scatter plots (with braille marker), bar charts, histograms, stacked bars, subplots, date axes, and even inline image display, making it the richer choice when your CLI tool needs multiple chart types. For the uniplot alternative — uniplot renders Unicode braille charts with superior visual resolution and good NumPy/pandas integration via its plot() function, but is line/scatter focused; plotext has a more complete API covering bar, histogram, subplot grids, and theming, making it better for dashboard-style CLI output. The Claude Skills 360 bundle includes plotext skill sets covering plt.plot()/scatter()/bar()/hist() core charts, multi_line_chart() multi-series overlay, bar_chart() vertical and horizontal, stacked_bar_chart(), histogram() and multi_histogram(), grid_dashboard() subplot grid, LiveChart deque-backed scrolling display, from_series()/from_dataframe() pandas integration, plt.theme() dark/pro/matrix styles, plt.build() for string capture, and plt.plotsize() for fixed dimensions. Start with the free tier to try terminal chart code generation.

Keep Reading

AI

Claude Code for email.contentmanager: Python Email Content Accessors

Read and write EmailMessage body content with Python's email.contentmanager module and Claude Code — email contentmanager ContentManager for the class that maps content types to get and set handler functions allowing EmailMessage to support get_content and set_content with type-specific behaviour, email contentmanager raw_data_manager for the ContentManager instance that handles raw bytes and str payloads without any conversion, email contentmanager content_manager for the standard ContentManager instance used by email.policy.default that intelligently handles text plain text html multipart and binary content types, email contentmanager get_content_text for the handler that returns the decoded text payload of a text-star message part as a str, email contentmanager get_content_binary for the handler that returns the raw decoded bytes payload of a non-text message part, email contentmanager get_data_manager for the get-handler lookup used by EmailMessage get_content to find the right reader function for the content type, email contentmanager set_content text for the handler that creates and sets a text part correctly choosing charset and transfer encoding, email contentmanager set_content bytes for the handler that creates and sets a binary part with base64 encoding and optional filename Content-Disposition, email contentmanager EmailMessage get_content for the method that reads the message body using the registered content manager handlers, email contentmanager EmailMessage set_content for the method that sets the message body and MIME headers in one call, email contentmanager EmailMessage make_alternative make_mixed make_related for the methods that convert a simple message into a multipart container, email contentmanager EmailMessage add_attachment for the method that attaches a file or bytes to a multipart message, and email contentmanager integration with email.message and email.policy and email.mime and io for building high-level email readers attachment extractors text body accessors HTML readers and policy-aware MIME construction pipelines.

5 min read Feb 12, 2029
AI

Claude Code for email.charset: Python Email Charset Encoding

Control header and body encoding for international email with Python's email.charset module and Claude Code — email charset Charset for the class that wraps a character set name with the encoding rules for header encoding and body encoding describing how to encode text for that charset in email messages, email charset Charset header_encoding for the attribute specifying whether headers using this charset should use QP quoted-printable encoding BASE64 encoding or no encoding, email charset Charset body_encoding for the attribute specifying the Content-Transfer-Encoding to use for message bodies in this charset such as QP or BASE64, email charset Charset output_codec for the attribute giving the Python codec name used to encode the string to bytes for the wire format, email charset Charset input_codec for the attribute giving the Python codec name used to decode incoming bytes to str, email charset Charset get_output_charset for returning the output charset name, email charset Charset header_encode for encoding a header string using the charset's header_encoding method, email charset Charset body_encode for encoding body content using the charset's body_encoding, email charset Charset convert for converting a string from the input_codec to the output_codec, email charset add_charset for registering a new charset with custom encoding rules in the global charset registry, email charset add_alias for adding an alias name that maps to an existing registered charset, email charset add_codec for registering a codec name mapping for use by the charset machinery, and email charset integration with email.message and email.mime and email.policy and email.encoders for building international email senders non-ASCII header encoders Content-Transfer-Encoding selectors charset-aware message constructors and MIME encoding pipelines.

5 min read Feb 11, 2029
AI

Claude Code for email.utils: Python Email Address and Header Utilities

Parse and format RFC 2822 email addresses and dates with Python's email.utils module and Claude Code — email utils parseaddr for splitting a display-name plus angle-bracket address string into a realname and email address tuple, email utils formataddr for combining a realname and address string into a properly quoted RFC 2822 address with angle brackets, email utils getaddresses for parsing a list of raw address header strings each potentially containing multiple comma-separated addresses into a list of realname address tuples, email utils parsedate for parsing an RFC 2822 date string into a nine-tuple compatible with time.mktime, email utils parsedate_tz for parsing an RFC 2822 date string into a ten-tuple that includes the UTC offset timezone in seconds, email utils parsedate_to_datetime for parsing an RFC 2822 date string into an aware datetime object with timezone, email utils formatdate for formatting a POSIX timestamp or the current time as an RFC 2822 date string with optional usegmt and localtime flags, email utils format_datetime for formatting a datetime object as an RFC 2822 date string, email utils make_msgid for generating a globally unique Message-ID string with optional idstring and domain components, email utils decode_rfc2231 for decoding an RFC 2231 encoded parameter value into a tuple of charset language and value, email utils encode_rfc2231 for encoding a string as an RFC 2231 encoded parameter value, email utils collapse_rfc2231_value for collapsing a decoded RFC 2231 tuple to a Unicode string, and email utils integration with email.message and email.headerregistry and datetime and time for building address parsers date formatters message-id generators header extractors and RFC-compliant email construction utilities.

5 min read Feb 10, 2029

Put these ideas into practice

Claude Skills 360 gives you production-ready skills for everything in this article — and 2,350+ more. Start free or go all-in.

Back to Blog

Get 360 skills free