Skip to main content

Educational library to directly plot single data points

Project description

python-directplot

Educational library to directly plot single data points.

Description

Educational library to directly plot single data points.

ATTENTION: This library is slow and not suited for production use!

It has been developed for educational purpose, especially to visualize numerical algorithms e.g. for simulation or plotting measurement data.

It wraps matplotlib and pyplot commands in even simpler commands:

import math
import directplot as dp

dp.init()

for i in range(51):
    x = i*2*math.pi/50
    y = math.sin(x)
    dp.add(0, x, y)

dp.waitforclose()

The following functions are provided:

  • init() Initializes and opens a Direct Plot window
  • add() Adds a single point to a plot line
  • showMarker() Shows or hides marker points on a plot line or on all plot lines
  • label() Changes the label of a plot line used in the legend
  • title() Changes the title of a sub-plot
  • xylabel() Changes the axis lables of a sub-plot
  • refresh() Refreshes the contents of the plot window
  • close() Closes the Direct Plot window
  • clear() Deletes the contents of the plot window
  • waitforclose() Updates the title on the plot window and blocks execution until user closes the plot window.

API

Functions are listed alphabetical order. Unless otherwise noted, the return type is None.

add()

Adds a single point to a plot line.

If the number of points per plot line exceeds maxPoints (see init()), the oldest point is removed automatically, resulting in a scroll behavior of the plots.

add(id, x, y, refresh=True)

Parameter:

  • id (int) – The id of the target plot line
  • x (float) – x value
  • y (float) – y value
  • refresh (bool) – Determines if the plot is refreshed immediately resulting in slower plotting speed. Optional with default True

Example

dp.add(0, 0.1, 2.7)
dp.add(1, 1.1, 7.3, False)
dp.add(1, 1.2, 7.2)

clear()

Deletes the contents of the plot window.

Keeps the number of sub-plots, the number of lines per sub-plot and the titles of the sub-plots. Everything else is reset/deleted.

clear()

Example

dp.clear()

close()

Closes the Single Point Plot window.

close()

Example

dp.close()

init()

Initializes and opens a Single Point Plot window.

init(titles=['Single-Point-Plot'], linesPerSubplot=4, showMarker=True, maxPoints=10000, grid: bool = True)

Parameter

  • titles (list(str)) – A list or tuple containing 1 to 3 strings, resulting in 1 to 3 sub-plots on the plot window. Optional with a default title for a single sub-plot.
  • linesPerSubplot (int) – Number of lines (data series) per sub-plot. Optional with default 4
  • showMarker (bool) – Determines if data points are emphasized with a little dot. Optional with default True
  • maxPoints (int) - Maximum number of data points per line (data series). Optional with default 10000
    If the number of points per plot line exceeds maxPoints, the oldest point is removed automatically, resulting in a scroll behavior of the plots.
  • grid (bool): Display plot grid. Optional with default True

Example

dp.init()

or

dp.init(["Results"])

or

dp.init(["Height", "Speed", "Forces"], linesPerSubplot=2, showMarker=False)

or

dp.init(["Temperature °C", "Pressure mbar", "Humidity %"], linesPerSubplot=1,  maxPoints=100)

label()

Changes the label of a plot line used in the legend.

label(id, label)

Parameter

  • id (int) – The id of the target plot line
  • label (str) – The new label text

Example

dp.label(0, "mass in kg")

refresh()

Refreshes the contents of the plot window.

Mostly used in conjunction with add() and refresh=False.

refresh()

Example

dp.add(0, 0.1, 7.3, False)
dp.add(0, 0.2, 6.9, False)
dp.add(0, 0.3, 2.1, False)
dp.refresh()

showMarker()

Shows or hides marker points on a plot line or on all plot lines.

showMarker(show=True, id=None)

Parameter

  • show (bool) – Show or hide markes. Optional with default True
  • id (int) – The id of the target plot line. Optional with default None resulting in a change of markers on all plot lines.

Example

dp.showMarker()

or

dp.showMarker(False, 1)

title()

Changes the title of a sub-plot

title(id, title)

Parameter

  • id (int) – The id of the target plot line used to determine the corresponding sub-plot
  • title (str) – The new title text

Example

dp.title(0, "Simulated Values")

waitforclose()

Updates the title on the plot window and blocks execution until user closes the plot window.

waitforclose(msg=None)

Parameter

  • msg (str) – A string to be shown on the window title and on stdout. Optional with default None resulting in a standard title

Example

dp.waitforclose()

or

dp.waitforclose("PLEASE CLOSE THE DIRECT PLOT WINDOW")

xylabel()

Changes the axis lables of a sub-plot.

xylabel(id, xlabel, ylabel)

Parameter

  • id (int) – The id of the target plot line used to determine the corresponding sub-plot
  • xlabel (str) – New label for the x axis
  • ylabel (str) – New label for the y axis

Example

dp.xylabel(0, "time in s", "force in N")

Development

Build pypi package

Tools needed to build and publish to PyPi under Windows:

python -m pip install --upgrade build
python -m pip install --upgrade twine

Tools needed to build and publish to PyPi Linux/MacOS:

python3 -m pip install --upgrade build
python3 -m pip install --upgrade twine

Build package:

python -m build

Upload package to pypi:

Before uploading, delete outdated build artifacts in the dist folder, such that only the latest build files are uploaded.

twine upload dist/*

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

directplot-0.5.2.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

directplot-0.5.2-py3-none-any.whl (9.4 kB view details)

Uploaded Python 3

File details

Details for the file directplot-0.5.2.tar.gz.

File metadata

  • Download URL: directplot-0.5.2.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for directplot-0.5.2.tar.gz
Algorithm Hash digest
SHA256 2e322b39e70df0dfcc9ddb4bfa613d63fd705a43fc01f3a444799b7c0dbef341
MD5 adfd88ddf0eef6d0029b60904ff349d2
BLAKE2b-256 7dd42c721c31658cfa69b7a6f595f706d9439e53adc504bd8e25edcd4c812745

See more details on using hashes here.

File details

Details for the file directplot-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: directplot-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 9.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.10

File hashes

Hashes for directplot-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b90d8d41cb6826bbe156ab154152f64e22842a27e9c9c4efb70b66d545ac4bf9
MD5 4e3056d21806a2cde0773a7670386e28
BLAKE2b-256 89ac1761783ebd83c58c3719595c9c110922351a44604db5aabdb08e4d5f86fc

See more details on using hashes here.

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