The following shows an example of a simple data viewer which includes
a slider, a bitmap, and a scatter plot:
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.widgets import Slider
fig = plt.figure()
ax1 = fig.add_axes([0.1, 0.1, 0.4, 0.7])
image = ax1.imshow(np.random.random((512, 512)), vmin=0., vmax=1.)
ax2 = fig.add_axes([0.1, 0.9, 0.85, 0.05])
slider = Slider(ax2, "", 0., 1.)
ax3 = fig.add_axes([0.55, 0.1, 0.4, 0.7])
x = np.random.random(10000)
y = np.random.random(10000)
When moving the slider, the vmax of the image changes, but I get very
slow frame rates (~2/sec) on my computer with the MacOS X backend. I
was wondering whether people here have any tips on speeding things up?
As far as I can figure out, this is slow because both the slider and
the callback function call ``fig.canvas.draw``. Slider calls it before
the callback function, so I definitely need to draw things in that
function, but I can get a factor of 2x speedup by doing
slider.drawon = False
which prevents ``canvas.draw()`` being called twice. However, this is
still much too slow, so I started to look into using ``draw_artist``
to only update elements that need updating, but this requires
partially re-implementing the Slider class.
As a side note, using ``draw_artist`` also does not work on the MacOS X backend:
but I'm willing to have a solution that wouldn't work on this backend
if it was the only way.
Does anyone have a clean solution to increasing the frame rate of this example?