canvas.restore_region()不起作用 [英] canvas.restore_region() not working

查看:34
本文介绍了canvas.restore_region()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图按照以下说明进行操作: http://wiki.scipy.org/Cookbook/Matplotlib/Animations

I was trying to follow the instructions on: http://wiki.scipy.org/Cookbook/Matplotlib/Animations

为什么下面的代码没有显示预期的行为?(请参阅代码中有关预期与观察到的内容的注释)

Why is the code below not showing the expected behaviour? (see comments in code on what is expected vs. what is observed)

import matplotlib.pyplot as plt
from pylab import rand

f, ax = plt.subplots()

# Generate dummy plot
ax.set_xlim([0, 10])
ax.set_ylim([0, 10])
ax.imshow(rand(10,10),  interpolation='nearest')
# Until here it works
# If i would add a 
#     f.show() 
# i would see the image

# Save figure
canvas = ax.figure.canvas
background = canvas.copy_from_bbox(ax.bbox)  

# Clear Axes
ax.cla()

# try to restore figure
canvas.restore_region(background)
f.show()

# Unfortunatly I only see an empty figure now, Why??

后续问题:

  • 我打算在同一轴上的修改后的位置上生成 background 的半透明副本.(如何)这可能吗?
  • I intent to generate a semi transparent copy of background on an modified Position in the same axes. (How) Is this possible?

推荐答案

正如@tcaswell 所说,你需要强制一个 draw() 调用 begore background = canvas.copy_from_bbox(ax.bbox).试试

As @tcaswell said, you need to force a draw() call begore background = canvas.copy_from_bbox(ax.bbox). Try

...
canvas = ax.figure.canvas
canvas.draw()
background = canvas.copy_from_bbox(ax.bbox)  
...

这篇关于canvas.restore_region()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆