TCLab Plotter¶
When operating in a Jupyter Notebook, a Plotter
can be used together with the Historian
.
h = Historian(lab)
p = Plotter(h, tfinal)
where lab
is a TCLab
instance as before and the optional parameter tfinal
provides an initial scaling of the time axes. Each call to p.update()
will automatically update both the historian and the plot.
[1]:
%matplotlib notebook
from tclab import TCLab, clock, Historian, Plotter, setup
TCLab = setup(connected=False, speedup=10)
with TCLab() as lab:
h = Historian(lab.sources)
p = Plotter(h, twindow=200)
for t in clock(200):
lab.Q1(100 if t < 100 else 0)
p.update(t)
Simulated TCLab
TCLab Model disconnected successfully.
Specifying layout¶
The layout of values can be speficied when creating a Plotter
. Layout is given as a tuple of tuples. Each of the first level tuples creates a new axis, and each of the elements in the tuple is plotted on that same axis.
[2]:
%matplotlib notebook
from tclab import setup
from tclab import Historian, Plotter, clock
import time
tic = time.time()
TCLab = setup(connected=False, speedup=10)
with TCLab() as lab:
h = Historian(lab.sources)
p = Plotter(h, 200, layout=(('T1', 'T2'), ('Q1', 'Q2')))
for t in clock(200):
lab.U1 = 80
p.update(t)
toc = time.time()
print(toc-tic, 'seconds')
Simulated TCLab
TCLab Model disconnected successfully.
20.255380153656006 seconds
[ ]: