This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

trying to plot multiple eigenvectors

0 votes

Sorry for the basic question but I am trying to plot the real and the imaginary parts of the eigenvector that I obtain from solving an eigenvalue problem. I am trying to follow a model that I found online and the first figure comes up. But when I close it the system seems to freeze and I need to force quit python.

I am running this on my Mac and using the FEniCS binary. Below is the tail end of my code. Any advice would be greatly appreciated.

psi = Function(V0)
psi_vec = psi.vector()

for i in range(num):
r, c, rx, cx = eigensolver.get_eigenpair(i)
print("Eigenvalue:", i, r, c)

  psi_vec[:] = rx
  psi_r = psi_vec[:]
  #psi_vec[:] = cx
  #psi_i = psi_vec[:]

  # Plot eigenfunction
  plot(psi, key='u', title='psi_r')
  interactive()
closed with the note: The problem was resolved
asked Mar 22, 2016 by fpoulin FEniCS Novice (200 points)
closed Apr 7, 2016 by fpoulin

Hi, how about not including interactive() in the for loop. I mean

for i in range(num):
    # your code here
interactive()

Thank you. That did help a lot.

Now it shows me all of the plots, but very quickly. 

Is there a way to require that I click to proceed from one plot to the next? Or maybe put in a pause?

I tried inserting interactive=True in the plot and that froze things as before, so clearly that's not the right thing to do.

Unfortunately I don't have a setup to reproduce your exact problem. If the plots stay alive after the loop then I suggest plotting each vector as a new function. Something like

for i in range(num):
    r, c, rx, cx = eigensolver.get_eigenpair(i)
    print "%d:  %g" % (0, r)
    plot(Function(V0, rx), title='%d real' % i)
interactive()

Thank you. That worked much better.

The figures take up the full screen but I can see the different figures so my problem is resolved.

Much appreciated.

...