Update a graph while you plot!
From PIP:
$ pip install plot-on-the-go
example.output.mov
Code (sorting functions not shown):
from plot_on_the_go.plot import Scatter
from random_typing import List, Int
import timeit
grapher = Scatter(1000)
grapher.legend(red='bubble', blue='merge')
grapher.title('Bubble sort vs Merge sort')
for length in range(1001):
l = List(Int(1, 100), length)
b = timeit.timeit('bubble_sort(lst)',
globals={'lst': next(l), 'bubble_sort': bubble_sort},
number=1) * 1000
m = timeit.timeit('merge_sort(lst)',
globals={'lst': next(l), 'merge_sort': merge_sort},
number=1) * 1000
grapher.plot_point(length, b, 'red')
grapher.plot_point(length, m, 'blue')
grapher.show()
Note: this program uses random-typing to generate random lists of integers
from plot_on_the_go.plot import Scatter
grapher = Scatter(1000)
The parameter is the maximum x-value
grapher.plot_point(0, 1, 'red')
The parameters are:
x
: int or floaty
: int or floatcolour
: see section on accepted colours.
grapher.legend(red='v1', blue='v2')
Colours must be from the table linked in the accepted colours section.
grapher.title('My graph')
grapher.show()
grapher.stop()
example.output.2.mov
Code (sorting functions not shown):
from plot_on_the_go.plot import Bar
from random_typing import List, Int
import timeit
grapher = Bar()
grapher.title('Bubble sort vs Merge sort - runs/sec')
for length in range(1001):
l = List(Int(1, 100), length)
b = 1 / timeit.timeit('bubble_sort(lst)',
globals={'lst': next(l), 'bubble_sort': bubble_sort},
number=1)
m = 1 / timeit.timeit('merge_sort(lst)',
globals={'lst': next(l), 'merge_sort': merge_sort},
number=1)
grapher.add_num('bubble', b)
grapher.add_num('merge', m)
grapher.show()
from plot_on_the_go.plot import Scatter
grapher = Bar()
The parameter (optional) is the function to apply to a list of numbers, which should return a number. It defaults to sum
grapher.plot_point('a', 1)
The parameters are:
label
- the label to add the point toy
- the number to add
grapher.title('My graph')
grapher.show()
grapher.stop()
Colours can be given in two formats
-
A tuple, (r, g, b), of three int or floats. E.g.
(100, 123.4, 255)
-
An acceptable string - any colour in this table