Skip to main content

Get your plot in you array, plot fast

Project description

Why not just get your plots in numpy?!

Why not just have a simple API

plot(values, grid_options, figure_options, ...) -> (figures, grid, axis,labels)

which renders plot in numpy/tensors and you can overlay, mask, transform, publish in any way you want whilst fully controlling every detail of your plot and figures?

Installation

pip install justpyplot

JustPyPlot: Fast NumPy-Native Plotting

So Why Yes?

  • Fast: Vectorized plotting directly to NumPy arrays - no memory screenshots or buffer copies A high-performance plotting library that renders directly to NumPy arrays. Measured 20-100x faster than matplotlib:
timer "full justpyplot + rendering": avg 382 µs ± 135 µs, max 962 µs
  • Simple: Get all plots parts as arrays with a single function call
figure, grid, axis, labels = jplt.plot(values,grid_opts,figure_opts,title,(600, 400))

and put them on, in or into everwhere you need in 1-2 subsequent lines

  • Flexible: Control every plot element (figures, grid, axis, labels) and every detail of plotting options independently, all design options are parsed from json-style figure and grid option dicts with full documentation available: https://justpyplot.readthedocs.io/en/latest/

  • No dependencies: Just vectorized python with numpy(+ other tensor lib you need), which makes standalone and compatible with any use case

  • Small Less then 20K total and 1000 total of core code which you can all understand

  • Real-time: Was initially scrapped for computer vision and robotics for real-time visualization and physical debugging tasks where standard plotting failed

  • ML/AI Pluggable: You can, for example stick it onto visual layers of neural network for it to learn your plotted characteristic without changing any dimensions.

BASIC USAGE

Basic Usage

You can explore the documentation for the plot function which supports any flexing or adjusting of the plot as you need such as colors, scatter, connected with line thickness, labels, etc.

import numpy as np 
import cv2
import time
from justpyplot import justpyplot as jplt

t0 = time.perf_counter()
xs, ys = [], []

while(cv2.waitKey(1) != 27):  # Press ESC to exit
    xt = time.perf_counter() - t0
    yx = np.sin(xt)
    xs.append(xt)
    ys.append(yx)
    
    # Create plot data array
    plot_data = np.array([xs, ys])
    
    # Generate plot arrays with customized options
    figure, grid, labels, title_img = jplt.plot(
        plot_data,
        grid={'nticks': 5, 'color': (128, 128, 128, 255)},
        figure={'scatter': True, 'line_color': (255, 0, 0, 255), 'line_width': 2},
        title="sin() from Clock",
        size=(600, 400)
    )
    
    # Blend all plot layers into single image
    plotted_array = jplt.blend(figure, grid, labels, title_img)
  
    
    cv2.imshow('np array plot', plotted_array)

Overlaying Multiple Plots

You take to take your plot which you can mask, stretch, transform and render wherever in frame array/canvas/memory you need and just overlay it simpler in one line?

Here 1-liner function implementing those basic steps stuck on running mug neural network. In 3 lines of code it shows how to mess and visually debug 3d position of computer vision/robotics object in physical world (try in examples/mug_objectron/demo.py):

Overlaying multiple plots

jplt.plot1_at(image, ang_zs,
            title='Angle from Z axis', offset=(50,50), size=(270, 300),
            point_color=(255,0,0),line_color=(255,0,0), label_color=(255,0,0), grid_color=(126,126,126))
jplt.plot1_at(image, ang_ys,
          title='Angle from Y axis', offset=(400,50), size=(270, 300),
          point_color=(0,255,0), line_color=(0,255,0),label_color=(0,255,0), grid_color=(126,126,126),
          scatter=False)
jplt.plot1_at(image,ang_xs,
          title='Angle from X axis', offset=(750,50), size=(270, 300),
          point_color=(0,0,255), line_color=(0,0,255),label_color=(0,0,255), grid_color=(126,126,126),
          scatter=False)

Jupyter Notebook Usage

For jupyter support you can render images anyhow you like. One of the simplest is to use the blend2PIL function depening on Pillow package which will blend all the plot layers into a single PIL image buffer which you display in notebook

import numpy as np
from IPython.display import Image as ipyImage, display
from justpyplot import justpyplot as jplt

# Make some dependency data
x = np.linspace(0, 10, 50)
y = np.sin(x)

# Just plot in numpy using the plot() function
figure_img, grid_img, labels_img, title_img = jplt.plot(
    np.array([x, y]),
    grid={'nticks': 10, 'color': (128, 128, 128, 255), 'label_color': (255, 0, 0, 255),'precision': 1, 'label_font_size': 0.9},
    figure={'scatter':False,'point_color': (255, 0, 0, 255), 'point_radius':3, 'line_color':(0,64,64, 255), 'line_width': 2, 'marker_style':'circle'},
    title='Sine Wave',
    size=(300, 400),
    max_len=100
)

# blend arrays into PIL picture buffer (requires Pillow)
buffer = jplt.blend2PIL(grid_img, figure_img, labels_img, title_img, format='PNG')

# Display the image
display(ipyImage(buffer.getvalue()))

Jupyter Plot Output

Documentation

Documentation is fully available at https://justpyplot.readthedocs.io/en/latest/

Project details


Download files

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

Source Distribution

justpyplot-0.2.4.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

justpyplot-0.2.4-py2.py3-none-any.whl (21.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file justpyplot-0.2.4.tar.gz.

File metadata

  • Download URL: justpyplot-0.2.4.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for justpyplot-0.2.4.tar.gz
Algorithm Hash digest
SHA256 43a79eb104544058a744d8dce40a4065f8578762822374029b82337d2ef2be1d
MD5 063093e65a4f0af17bdeb86c6927161a
BLAKE2b-256 dbe6a68067a5e008edba57ad9c8cae4f51a45bcb4f69780a525c13bed86feffd

See more details on using hashes here.

Provenance

The following attestation bundles were made for justpyplot-0.2.4.tar.gz:

Publisher: python-publish.yml on bedbad/justpyplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file justpyplot-0.2.4-py2.py3-none-any.whl.

File metadata

  • Download URL: justpyplot-0.2.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 21.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for justpyplot-0.2.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 f5fe3a2071b5e0059592ca3f7a2445244f4446af4be50491964e0f528a5ed8ec
MD5 98a559543c7cccc0db00fbaad1e57797
BLAKE2b-256 a8d6541b028cb8351abcb815d4548911a649565b9b845047032754e9df0448d4

See more details on using hashes here.

Provenance

The following attestation bundles were made for justpyplot-0.2.4-py2.py3-none-any.whl:

Publisher: python-publish.yml on bedbad/justpyplot

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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