The challenge seemed pretty easy, to assemble an easy demo with simple example :
- One example on how to use text entry in matplotlib that doubles with a 2D plotter,
- and the one from matplotlib on how to draw a 3D surface with a colorbar
- and the one for projecting the contour of the function on the axis
Without the colorbar I would have just been slightly annoyed by the slowness of the reaction of matplotlib as a GUI, but the colorbar posed a new challenge because it would either stack for each drawing or make plt.clf/ax.cla erase too much (see this great resource on when to use cla/clf in matplotlib).
So ... I tried python-tk with matplotlib knowing all too well that you can embed natively matplotlib in tkinter interface.
And since it was working I kept it.
Here is a screenshot of the interface : WARNING this code should not be let in inventive hands (such as bored teenagers) because there is an evil eval; it requires to be in care of consenting adults.
Some highlights of the code :
- bidir python-tk requires setting the Popen PIPEs to non blocking and using select.select on the output
- matplotlib is unusable in non blocking mode : once matplotlib has the focus you need to destroy it to plot another function
- from np import * is evil, but it let you have access to all array oriented math function (sin, cos, exp, ...)
No comments:
Post a Comment