Contour/Contourf dynamically with slider

Hi all,

I want to make a contout plot with a slider element. But I am not sure if it
is possible at all and if it is possible how.

The code is a mixture of two examples I found in the web. One part is the
slider example of matplotlib

from pylab import *

N = 50
x = linspace(.0, 1.0, N)
y = linspace(.0, 1.0, N)
X, Y = meshgrid(x, y)
Z = sin(X+16) - 2*cos(Y*5.2)
c = contourf(X, Y, Z,20)
colorbar()

# Copied from the slider example ... not sure about the syntax
axfreq = axes([0.25, 0.1, 0.65, 0.03])
sfreq = Slider(axfreq, 'Amp', 0.1, 10.0, valinit=1)
def update(val):
  global sfreq
  freq = sfreq.val
  Z = sin(freq*X+16) - 2*cos(Y*5.2)
  c.set_data(Z) # Is something like that possible
  draw()
sfreq.on_changed(update)
show()

I tried different stuff, but could not solve the problem. Perhaps anybody
has an idea to help me.

Thank you!

          Best regards
             Stefan

···

--
View this message in context: http://old.nabble.com/Contour-Contourf-dynamically-with-slider-tp30698071p30698071.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

Hi all,

I want to make a contout plot with a slider element. But I am not sure if it
is possible at all and if it is possible how.

With contouring, you have to simply remake the ContourSet (that is, re-run contour) with any change to the data being contoured.

Eric

···

On 01/17/2011 10:24 PM, sprobst wrote:

The code is a mixture of two examples I found in the web. One part is the
slider example of matplotlib

from pylab import *

N = 50
x = linspace(.0, 1.0, N)
y = linspace(.0, 1.0, N)
X, Y = meshgrid(x, y)
Z = sin(X+16) - 2*cos(Y*5.2)
c = contourf(X, Y, Z,20)
colorbar()

# Copied from the slider example ... not sure about the syntax
axfreq = axes([0.25, 0.1, 0.65, 0.03])
sfreq = Slider(axfreq, 'Amp', 0.1, 10.0, valinit=1)
def update(val):
  global sfreq
  freq = sfreq.val
  Z = sin(freq*X+16) - 2*cos(Y*5.2)
  c.set_data(Z) # Is something like that possible
  draw()
sfreq.on_changed(update)
show()

I tried different stuff, but could not solve the problem. Perhaps anybody
has an idea to help me.

Thank you!

           Best regards
              Stefan