Matplotlib hooks for xonsh, including the new 'mpl' alias that displays the current figure on the screen.
If you like the idea click ⭐ on the repo and tweet.
To install use pip:
xpip install -U git+https://github.com/xonsh/xontrib-mpl
# todo: xpip install xontrib-mplxontrib load mplExamples: https://youtu.be/uaje5I22kgE?t=1362
Sample CPU utilisation once per second for 10 seconds, build a line chart, and render it right in the terminal — no GUI window needed:
xpip install psutil
xontrib load mpl
import psutil
import matplotlib.pyplot as plt
samples = []
N = 10
for i in range(N):
perc = psutil.cpu_percent(interval=1)
samples.append(perc)
print(f'CPU {i+1}/{N}: {perc}%')
plt.close('all') # discard previous figures so re-runs don't overlay
plt.plot(samples)
plt.ylim(0, 100) # fixed 0–100% so re-runs are visually comparable
mplThe figure is rasterised into coloured terminal cells and printed inline below your prompt.
Tip:
mpldefaults to$XONTRIB_MPL_MINIMAL = True, which hides tick labels, axes text and inter-subplot gaps so the plot uses the full terminal. Set it toFalse($XONTRIB_MPL_MINIMAL = False) to keep the title / xlabel / ylabel you'd normally pass to matplotlib.
If you want to use matplotlib day to day with xonsh we recommend to take a look into xontrib-jupyter that could be used both in web-based Jupyter Notebook and in terminal with Euporia.
This package was created with xontrib cookiecutter template.