Skip to main content

Legible console plotting in Python.

Project description

ANSIplot

Compatibility

A small utility library for legible console plotting in Python. Plot differences remain mostly legible, even for highly overlapping plots and small canvas dimensions. ANSI is used to color console output.

Quickstart

Install the library with pip install ansiplot. Then prepare some data for drawing three curves: two similar cosine functions that lie very close to each other, and a sine function.

import math

x = [(i - 100) * 0.01 for i in range(200)]
y1 = [math.cos(value * 10) for value in x]
y2 = [math.cos(value * 10 + 0.1) for value in x]
y3 = [math.sin(value * 10) for value in x]

Now, import ansiplot and create a rectangle 60x10 canvas. This has specific scaling limits, but you can also use a Scaled canvas to automatically detect those limits. For demonstration purposes, hide the default axis to add some on specific locations at the end with bar and hbar. Those forcefully rewrite entries, whereas other plots try to preserve some overwritten information from being hidden if they can help it.

import ansiplot

plot = ansiplot.Rect(60, 10, 
     xlimits=(-1, 1), 
     ylimits=(-1, 1), 
     axis=False)
plot.plot(x, y1, title="cos")
plot.plot(x, y2, title="cos offset")
plot.plot(x, y3, title="cos")
# plot a custom axis
plot.bar(0, (-1, 1), symbol="▕▎");
plot.hbar((-1, 1), 0, symbol=Pretty.xaxis, title="x=0 or y=0")
# show
plot.show()

Example image

You can export the text manually with plot.text(). Both this and the show method can create colorless versions (useful for exporting to files) and control whether legends are shown. Here is an example for exporting the canvas to a file:

with open("example.txt", "w") as file:
    file.write(plot.text(colorless=True, legend=True))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

ansiplot-0.1.2-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file ansiplot-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: ansiplot-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.13.0

File hashes

Hashes for ansiplot-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8efdc73ce6d9383d8b057e09f06de8bbe08dfa6c324ebcf02bd32c6ef47a0698
MD5 5047f054904b8d475445a74ac465896e
BLAKE2b-256 64559268e71e87f32ba02019b1f7404f8403d2f923803e5fe0fce5ef283403fb

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page