home / skills / terrylica / cc-skills / plotext-financial-chart

plotext-financial-chart skill

/plugins/doc-tools/skills/plotext-financial-chart

This skill generates ASCII financial line charts using plotext in Markdown, enabling clear price paths and trading insights within GitHub-friendly text output.

npx playbooks add skill terrylica/cc-skills --skill plotext-financial-chart

Review the files below or copy the command above to add this skill to your agents.

Files (3)
SKILL.md
5.6 KB
---
name: plotext-financial-chart
description: ASCII financial line charts for markdown using plotext dot marker. TRIGGERS - financial chart, line chart, plotext, price chart, trading chart, ASCII chart.
allowed-tools: Read, Bash, Write, Edit
---

# Plotext Financial Chart Skill

Create ASCII financial line charts for GitHub Flavored Markdown using plotext with dot marker (`•`). Pure text output — renders correctly on GitHub, terminals, and all monospace environments.

**Analogy**: `graph-easy` is for flowcharts. `plotext` with dot marker is for financial line charts.

## When to Use This Skill

- Adding price path / line chart diagrams to markdown documentation
- Visualizing trading concepts (barriers, thresholds, entry/exit levels)
- Any GFM markdown file needing financial data visualization
- User mentions "financial chart", "line chart", "price chart", "plotext", or "trading chart"

**NOT for**: Flowcharts or architecture diagrams — use `graph-easy` for those.

## Preflight Check

### All-in-One Preflight Script

```bash
/usr/bin/env bash << 'PREFLIGHT_EOF'
python3 --version &>/dev/null || { echo "ERROR: Python 3 not found"; exit 1; }
if command -v uv &>/dev/null; then PM="uv pip"
elif command -v pip3 &>/dev/null; then PM="pip3"
else echo "ERROR: Neither uv nor pip3 found"; exit 1; fi
python3 -c "import plotext" 2>/dev/null || { echo "Installing plotext via $PM..."; $PM install plotext; }
python3 -c "
import plotext as plt, re
plt.clear_figure()
plt.plot([1,2,3], [1,2,3], marker='dot')
plt.plotsize(20, 5)
plt.theme('clear')
output = re.sub(r'\x1b\[[0-9;]*m', '', plt.build())
assert '•' in output
" && echo "✓ plotext ready (dot marker verified)"
PREFLIGHT_EOF
```

## Quick Start

```python
import re
import plotext as plt

x = list(range(20))
y = [97, 98, 100, 101, 100, 98, 100, 101, 102, 101,
     100, 98, 100, 101, 102, 103, 102, 101, 100, 100]

plt.clear_figure()
plt.plot(x, y, marker="dot", label="Price path")
plt.hline(103)    # Upper barrier
plt.hline(97)     # Lower barrier
plt.hline(100)    # Entry price
plt.title("Triple Barrier Method")
plt.xlabel("Time (bars)")
plt.ylabel("Price")
plt.plotsize(65, 22)
plt.theme("clear")
print(re.sub(r'\x1b\[[0-9;]*m', '', plt.build()))
```

## Mandatory Settings

Every chart MUST use these settings:

| Setting         | Code                        | Why                          |
| --------------- | --------------------------- | ---------------------------- |
| Reset state     | `plt.clear_figure()`        | Prevent stale data           |
| Dot marker      | `marker="dot"`              | GitHub-safe alignment        |
| No color        | `plt.theme("clear")`        | Clean text output            |
| Strip ANSI      | `re.sub(r'\x1b\[…', '', …)` | Remove residual escape codes |
| Build as string | `plt.build()`               | Not `plt.show()`             |

## Marker Reference

| Marker      | GitHub Safe | Use When                       |
| ----------- | ----------- | ------------------------------ |
| `"dot"`     | Yes         | **Default — always use**       |
| `"hd"`      | Yes         | Terminal-only, need smoothness |
| `"braille"` | No          | Never for markdown             |
| `"fhd"`     | No          | Never — Unicode 13.0+ only     |

## Rendering Command

```bash
/usr/bin/env bash << 'RENDER_EOF'
python3 << 'CHART_EOF'
import re
import plotext as plt

x = list(range(20))
y = [97, 98, 100, 101, 100, 98, 100, 101, 102, 101,
     100, 98, 100, 101, 102, 103, 102, 101, 100, 100]

plt.clear_figure()
plt.plot(x, y, marker="dot", label="Price path")
plt.hline(103)
plt.hline(97)
plt.hline(100)
plt.title("Triple Barrier Method")
plt.xlabel("Time (bars)")
plt.ylabel("Price")
plt.plotsize(65, 22)
plt.theme("clear")
print(re.sub(r'\x1b\[[0-9;]*m', '', plt.build()))
CHART_EOF
RENDER_EOF
```

## Embedding in Markdown (MANDATORY: Source Adjacent to Chart)

Every chart MUST be **immediately followed** by a `<details>` block with Python source. Explanatory text goes **after** the `<details>` block, never between chart and source.

```
✅ CORRECT: Chart → <details> → Explanatory text
❌ WRONG:   Chart → Explanatory text → <details>
```

See [./references/api-and-patterns.md](./references/api-and-patterns.md) for full embedding template.

## Mandatory Checklist

- [ ] `plt.clear_figure()` — Reset state
- [ ] `marker="dot"` — Dot marker for GitHub
- [ ] `plt.theme("clear")` + `re.sub()` strip — No ANSI codes
- [ ] `plt.title("...")` — Every chart needs a title
- [ ] `plt.xlabel` / `plt.ylabel` — Axis labels
- [ ] `plt.plotsize(65, 22)` — Fits 80-col code blocks
- [ ] `<details>` block **immediately after** chart (before any explanatory text)

## Troubleshooting

| Issue                 | Cause               | Solution                                      |
| --------------------- | ------------------- | --------------------------------------------- |
| ANSI codes in output  | Missing theme/strip | Add `plt.theme("clear")` and `re.sub()` strip |
| Misaligned on GitHub  | Wrong marker type   | Use `marker="dot"`, never braille/fhd         |
| Chart too wide        | plotsize too large  | Use `plt.plotsize(65, 22)` for 80-col blocks  |
| No diagonal slopes    | Too few data points | Use 15+ data points for visible slopes        |
| `ModuleNotFoundError` | Not installed       | Run preflight check                           |
| Empty output          | Missing `build()`   | Use `plt.build()` not `plt.show()`            |

## Resources

- [plotext GitHub](https://github.com/piccolomo/plotext)
- [Full API, patterns, and embedding guide](./references/api-and-patterns.md)
- [Tool selection rationale](./references/tool-selection.md)

Overview

This skill generates ASCII financial line charts for GitHub Flavored Markdown using plotext with the dot marker (•). It produces pure-text charts that render reliably in GitHub, terminals, and any monospace environment. The output is safe for inclusion in code blocks and paired with source in a <details> block for reproducible documentation.

How this skill works

The skill calls plotext to draw a line chart with marker="dot", sets a clear theme to avoid ANSI color codes, and uses plt.build() to capture the chart as a string. It strips any residual ANSI escape sequences, enforces mandatory settings (title, axis labels, plotsize, clear state), and returns a plain-text chart ready for embedding in Markdown. A small preflight script verifies plotext is available and that the dot marker renders as • before use.

When to use it

  • Embedding price-path or trading charts directly in Markdown documentation
  • Illustrating trading concepts like barriers, thresholds, or entry/exit levels
  • Adding lightweight visualizations to READMEs, design notes, or issue discussions
  • Creating terminal-friendly previews of financial data
  • When you need reproducible, source-adjacent charts for examples or tutorials

Best practices

  • Always call plt.clear_figure() before plotting to avoid stale state
  • Use marker="dot" (•) — it aligns in GitHub code blocks and is the required default
  • Apply plt.theme("clear") and strip ANSI escapes to ensure plain text output
  • Use plt.build() (not plt.show()) and print the resulting string
  • Include a title, xlabel, and ylabel for every chart and use plotsize 65x22 for 80-column code blocks
  • Place the Python source inside a <details> block immediately after the chart

Example use cases

  • Show a price path illustrating a triple-barrier backtest inside a README
  • Document entry and exit thresholds for a trading strategy in a tutorial
  • Embed a small time-series preview in an issue or design doc without images
  • Produce terminal-friendly sample charts for interactive demos or unit-test artifacts

FAQ

Why must I use marker="dot"?

The dot marker produces the • glyph which preserves alignment in GitHub code blocks and across monospace terminals. Other markers (braille, fhd) can break rendering or require newer Unicode support.

How do I ensure no ANSI color codes appear?

Call plt.theme("clear") before building the chart and run a regex strip (e.g., re.sub(r'\x1b\[[0-9;]*m','', plt.build())) to remove any lingering escape sequences.