• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

stsievert/python-drawnow: MATLAB-like drawnow to easily update a figure

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

stsievert/python-drawnow

开源软件地址(OpenSource Url):

https://github.com/stsievert/python-drawnow

开源编程语言(OpenSource Language):

Python 96.7%

开源软件介绍(OpenSource Introduction):

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 figure, drawnow. This repo brings the same feature to Python's matplotlib, with some extras.

Example:

image0

This is shown with imshow, but python-drawnow allows updates of any figure.

Usage:

# 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)

Documentation

If you want to wait for confirmation after update or the option to drop into a debugger, call drawnow(function_to_draw_figure, confirm=True).

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 drawnow? or help(drawnow) to see these docs.

Jupyter/Spyder

Try running the folloowing code in a Jupyter input cell/in the console/etc:

%matplotlib

This will disable the Matplotlin inline mode and use the default plotting backend. For more detail, see the IPython plotting documentation.

Installation

Two options:

  1. Run pip install drawnow.
  2. Download this repository and run python setup.py install.

Option 2 assumes a working Python installation with pip. I suggest Anaconda's distribution: https://www.anaconda.com/distribution/ For other options, see https://realpython.com/installing-python/.

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 much.




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap