A matplotlib backend that produces plots using only ASCII characters
Project description
mpl_ascii
A matplotlib backend that produces plots using only ASCII characters. It is available for python 3.9+.
Quick start
Install mpl_ascii using pip
pip install mpl_ascii
To use mpl_ascii, add to your python program
import matplotlib as mpl
mpl.use("module://mpl_ascii")
When you use plt.show() then it will print the plots as strings that consists of ASCII characters.
If you want to save a figure to a .txt file then just use figure.savefig("my_figure.txt")
See more information about using backends here: https://matplotlib.org/stable/users/explain/figure/backends.html
Examples
Bar chart
import matplotlib.pyplot as plt
import matplotlib as mpl
mpl.use("module://mpl_ascii")
import matplotlib.pyplot as plt
# Example data
fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [10, 15, 7, 5]
colors = ['red', 'blue', 'red', 'orange'] # Colors corresponding to each fruit
fig, ax = plt.subplots()
# Plot each bar individually
for fruit, count, color in zip(fruits, counts, colors):
ax.bar(fruit, count, color=color, label=color)
# Display the legend
ax.legend(title='Fruit color')
plt.show()
Scatter plot
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
mpl.use("module://mpl_ascii")
np.random.seed(0)
x = np.random.rand(40)
y = np.random.rand(40)
colors = np.random.choice(['red', 'green', 'blue', 'yellow'], size=40)
color_labels = ['Red', 'Green', 'Blue', 'Yellow'] # Labels corresponding to colors
# Create a scatter plot
fig, ax = plt.subplots()
for color, label in zip(['red', 'green', 'blue', 'yellow'], color_labels):
# Plot each color as a separate scatter plot to enable legend tracking
idx = np.where(colors == color)
ax.scatter(x[idx], y[idx], color=color, label=label)
# Set title and labels
ax.set_title('Scatter Plot with 4 Different Colors')
ax.set_xlabel('X axis')
ax.set_ylabel('Y axis')
# Add a legend
ax.legend(title='Point Colors')
plt.show()
Line plot
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
import mpl_ascii
mpl.use("module://mpl_ascii")
# Data for plotting
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
c = 1 + np.cos(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.plot(t, c)
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='About as simple as it gets, folks')
plt.show()
You can find more examples in the tests/accepted folder.
Use cases
Using Version Control for Plots
Handling plots with version control can pose challenges, especially when dealing with binary files. Here are some issues you might encounter:
-
Binary Files: Committing binary files like PNGs can significantly increase your repository’s size. They are also difficult to compare (diff) and can lead to complex merge conflicts.
-
SVG Files: Although SVGs are more version control-friendly than binary formats, they can still cause problems:
- Large or complex graphics can result in excessively large SVG files.
- Diffs can be hard to interpret.
To mitigate these issues, ASCII plots serve as an effective alternative:
- Size: ASCII representations are much smaller in size.
- Version Control Compatibility: They are straightforward to diff and simplify resolving merge conflicts.
This package acts as a backend for Matplotlib, enabling you to continue creating plots in your usual formats (PNG, SVG) during development. When you’re ready to commit your plots to a repository, simply switch to the mpl_ascii backend to convert them into ASCII format.
Feedback
Please help make this package better by:
- reporting bugs.
- making feature requests. Matplotlib is an enormous library and this supports only a part of it. Let me know if there particular charts that you would like to be converted to ASCII
- letting me know what you use this for.
If you want to tell me about any of the above just use the Issues tab for now.
Thanks for reading and I hope you will like these plots as much as I do :-)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpl_ascii-1.0.1.tar.gz.
File metadata
- Download URL: mpl_ascii-1.0.1.tar.gz
- Upload date:
- Size: 100.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c33911d47a8bd970f7ad0133695bd2d003a09a36d1a32fe74535d87f294dad5
|
|
| MD5 |
14a47b315c47fff20c081cd5906619ad
|
|
| BLAKE2b-256 |
5f025ad6ce56e3f7c545ed6a4096515d4a2bf6d88ad892ef41d7618941c2ce49
|
File details
Details for the file mpl_ascii-1.0.1-py3-none-any.whl.
File metadata
- Download URL: mpl_ascii-1.0.1-py3-none-any.whl
- Upload date:
- Size: 35.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c15e902309c0b5192d1fabefe61017b258566a9929da39c27f7b476240006d9b
|
|
| MD5 |
7f0a8da6c445cb641792088d8ad7e22d
|
|
| BLAKE2b-256 |
0a745a3396f1e594afed85324ec43fe069336e112db26461093647be074ce1c5
|