drawnow for matplotlib
The scientific community often runs iterative code, often in the form of
simulation. It's often useful to see the results after each iteration.
Accordingly, MATLAB® has a nice feature that allows you to update the
drawnow. This repo brings the same feature to Python's
matplotlib, with some extras.
This is shown with
imshow, but python-drawnow allows updates of any
# complete implementation of script found in test/test.py from pylab import * from drawnow import drawnow, figure # if global namespace, import plt.figure before drawnow.figure def approx(x, k): """Approximate x with k singular values""" ... figure(figsize=(7, 7/2)) def draw_fig(): subplot(1, 2, 1) imshow(x) subplot(1, 2, 2) imshow(x_hat) #show() x = imread('test-data/mandrill.png').mean(axis=2) k_values = around(logspace(0, 2, num=10)) for k in k_values: x_hat = approx(x, k) drawnow(draw_fig)
If you want to wait for confirmation after update or the option to drop
into a debugger, call
If you only want to show the figure once, call
drawnow(function_to_draw_figure, show_once=True). The full
documentation is included in the doc strings. Use
help(drawnow) to see these docs.
Try running the folloowing code in a Jupyter input cell/in the console/etc:
This will disable the Matplotlin inline mode and use the default plotting backend. For more detail, see the IPython plotting documentation.
pip install drawnow.
- Download this repository and run
python setup.py install.
Changes to code
This does require small changes to your code. All it should really
amount to is moving
figure(); plot(...); show() inside a function; not
Release history Release notifications | RSS feed
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size drawnow-0.72.5-py3-none-any.whl (4.3 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size drawnow-0.72.5.tar.gz (4.1 kB)||File type Source||Python version None||Upload date||Hashes View|