Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WebAgg backend #1426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jan 4, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions examples/widgets/slider_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons

ax = plt.subplot(111)
fig = plt.figure()
ax = fig.add_subplot(111)
plt.subplots_adjust(left=0.25, bottom=0.25)
t = np.arange(0.0, 1.0, 0.001)
a0 = 5
Expand All @@ -22,7 +23,7 @@ def update(val):
amp = samp.val
freq = sfreq.val
l.set_ydata(amp*np.sin(2*np.pi*freq*t))
plt.draw()
fig.canvas.draw_idle()
sfreq.on_changed(update)
samp.on_changed(update)

Expand All @@ -37,8 +38,7 @@ def reset(event):
radio = RadioButtons(rax, ('red', 'blue', 'green'), active=0)
def colorfunc(label):
l.set_color(label)
plt.draw()
fig.canvas.draw_idle()
radio.on_clicked(colorfunc)

plt.show()

7 changes: 5 additions & 2 deletions lib/matplotlib/animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,10 @@ class Animation(object):
'''
def __init__(self, fig, event_source=None, blit=False):
self._fig = fig
self._blit = blit
# Disables blitting for backends that don't support it. This
# allows users to request it if available, but still have a
# fallback that works if it is not.
self._blit = blit and fig.canvas.supports_blit
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems a little unfriendly. If I ask for blitting, I would expect to get it - otherwise I should get an error. What do you think?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This deserves some explanation. Some backends, such as WebAgg, do not support blitting. In the case of WebAgg, it's because blitting is not possible -- we don't have direct access to the window/screen buffers anyway, so there is no advantage to it. This allows code that was written to expect blitting (such as all of the examples/animation examples) to still work. There should be consistent behavior across backends, even when certain features are not available.


# These are the basics of the animation. The frame sequence represents
# information for each frame of the animation and depends on how the
Expand All @@ -543,7 +546,7 @@ def __init__(self, fig, event_source=None, blit=False):
# fire events and try to draw to a deleted figure.
self._close_id = self._fig.canvas.mpl_connect('close_event',
self._stop)
if blit:
if self._blit:
self._setup_blit()

def _start(self, *args):
Expand Down
11 changes: 0 additions & 11 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2116,17 +2116,6 @@ def redraw_in_frame(self):
def get_renderer_cache(self):
return self._cachedRenderer

def __draw_animate(self):
# ignore for now; broken
if self._lastRenderer is None:
raise RuntimeError('You must first call ax.draw()')
dsu = [(a.zorder, a) for a in self.animated.keys()]
dsu.sort(key=lambda x: x[0])
renderer = self._lastRenderer
renderer.blit()
for tmp, a in dsu:
a.draw(renderer)

#### Axes rectangle characteristics

def get_frame_on(self):
Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/backend_bases.py
Original file line number Diff line number Diff line change
Expand Up @@ -1482,6 +1482,8 @@ class FigureCanvasBase(object):
'close_event'
]

supports_blit = True
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it should be the other way around: By default a backend cannot blit, but if you implement the functionality, and toggle the switch, you get it...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's possible -- I was just trying to be backward compatible here with third-party backends that don't currently implement this value.


def __init__(self, figure):
figure.set_canvas(self)
self.figure = figure
Expand Down
Loading