plotext
plotext is a Python library that enables direct plotting on the terminal, offering a syntax highly similar to Matplotlib. It has no external dependencies for its core functionality and also provides a simple command-line tool for quick plotting. The library is actively maintained, with its latest version 5.3.2 released in September 2024, and features regular updates and improvements.
Warnings
- breaking Version 5.0 introduced significant changes, including a re-written codebase and changes to several function names and behaviors. Key removals/renames include `span()` (removed), `clear_plot()` (replaced by `clear_figure()`), and `xaxis()` (replaced by `xaxes()`). The logic for subplots was also redesigned.
- breaking Version 4.0 also involved a complete code re-write. Notably, the 'small' marker (for 2x2 resolution) was renamed to 'hd' (high definition).
- gotcha Some high-resolution markers (e.g., Unicode mosaic characters like braille) may not display correctly on all terminals, especially on Windows or when connecting via SSH, if the terminal font lacks support for these characters. This can result in '?' being displayed instead of the intended marker.
- gotcha Calling `plotext.show()` without any data, particularly when `plotext.interactive(True)` is enabled, can unexpectedly alter subsequent plots. The expected behavior is that `show()` with no data should not affect the plot state.
- gotcha There is a known issue where repeatedly calling `plotext.show()` or `plotext.build()` on a plot that uses a logarithmic scale (`xscale('log')` or `yscale('log')`) can lead to a `ValueError: math domain error` after the first successful display.
Install
-
pip install plotext
Imports
- plotext
import plotext as plt
Quickstart
import plotext as plt
import math
x = [i for i in range(0, 100)]
y = [math.sin(i / 10) for i in x]
plt.plot(x, y)
plt.title("Sine Wave Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()