Skip to main content

Legible console plotting in Python.

Project description

ANSIplot

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

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.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: ansiplot-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c83526765c714c6f6b444003f099e7d7a9d6b58f4f14fbe6259685dd5e72ce23
MD5 8d72680aa1fca79497367c2160d2e79d
BLAKE2b-256 439990570c55b7d576b856b452f4656335c76beacad03686471db1fb3ce3a8ee

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