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 windowadd()
Adds a single point to a plot lineshowMarker()
Shows or hides marker points on a plot line or on all plot lineslabel()
Changes the label of a plot line used in the legendtitle()
Changes the title of a sub-plotxylabel()
Changes the axis lables of a sub-plotrefresh()
Refreshes the contents of the plot windowclose()
Closes the Direct Plot windowclear()
Deletes the contents of the plot windowwaitforclose()
Displays a new window title on the plot window and blocks execution until user closes the window.
API
Functions are listed alphabetical order. Unless otherwise noted, the return type is None
.
add()
Adds a single point to a plot line.
add(id, x, y, refresh=True)
Parameter:
id
(int) – The id of the target plot linex
(float) – x valuey
(float) – y valuerefresh
(bool) – Determines if the plot is refreshed immediately resulting in slower plotting speed. Optional with defaultTrue
Example
spp.add(0, 0.1, 2.7)
spp.add(1, 1.1, 7.3, False)
spp.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
spp.clear()
close()
Closes the Single Point Plot window.
close()
Example
spp.close()
init()
Initializes and opens a Single Point Plot window.
init(titles=['Single-Point-Plot'], linesPerSubplot=4, showMarker=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 default4
showMarker
(bool) – Determines if data points are emphasized with a little dot. Optional with defaultTrue
Example
spp.init()
or
spp.init(["Results"])
or
spp.init(["Height", "Speed", "Forces"], 2, False)
label()
Changes the label of a plot line used in the legend.
label(id, label)
Parameter
id
(int) – The id of the target plot linelabel
(str) – The new label text
Example
spp.label(0, "mass in kg")
refresh()
Refreshes the contents of the plot window.
Mostly used in conjunction with add()
and refresh=False
.
refresh()
Example
spp.add(0, 0.1, 7.3, False)
spp.add(0, 0.2, 6.9, False)
spp.add(0, 0.3, 2.1, False)
spp.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 defaultTrue
id
(int) – The id of the target plot line. Optional with defaultNone
resulting in a change of markers on all plot lines.
Example
spp.showMarker()
or
spp.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-plottitle
(str) – The new title text
Example
spp.title(0, "Simulated Values")
waitforclose()
Displays a new window title on the plot window and blocks execution until user closes the window.
waitforclose(msg=None)
Parameter
msg
(str) – A string to be shown on the window title. Optional with defaultNone
resulting in a standard title
Example
spp.waitforclose()
or
spp.waitforclose("PLEASE CLOSE THIS 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-plotxlabel
(str) – New label for the x axisylabel
(str) – New label for the y axis
Example
spp.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:
twine upload dist/*
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
Hashes for directplot-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ff7cdbe921a8ea8e628452f0d3fd3a6130215df9e78f6ca1153486b84b7c0c45 |
|
MD5 | 2305a0a69f6833df0a960ad40468b0f3 |
|
BLAKE2b-256 | 2c61dc270db7830a1281a713684958d8addd5beb7c1a41f57da44d5850d30b17 |