Back to the main page.

Bug 3097 - create a figure handle output in ft_plot_dipole

Reported 2016-03-16 10:23:00 +0100
Modified 2019-08-10 12:33:06 +0200
Product: FieldTrip
Component: plotting
Version: unspecified
Hardware: PC
Operating System: Linux
Importance: P5 normal
Assigned to: Diego Lozano Soldevilla
Depends on:
See also:

Diego Lozano Soldevilla - 2016-03-16 10:23:28 +0100

ft_plot_dipole doesn't give any output, no figure handle. I want to plot a movie to show how a dipole changes both position and moment as a function of time. The problem consists that without a figure handle, all dipoles appear on the mri (using ft_plot_slice) Potential solution: In ft_plot_dipole, within lines 158-159 allow figure handles: h1=ft_plot_mesh(sphere, 'vertexcolor', 'none', 'edgecolor', false, 'facecolor', color); h2=ft_plot_mesh(stick, 'vertexcolor', 'none', 'edgecolor', false, 'facecolor', color); Problem: Do you know how to merge two figure handles?

Robert Oostenveld - 2016-03-16 12:39:37 +0100

without giving it a lot of thought, I would initially say that the ft_plot_xxx functions should not output a figure handle. Rather, they might have to output the handle (or handles) of the objects that they create. Those objects will have a parent, which has a parent, ... , which will lead to the axis and finally figure handle. If ft_plot_dipole were to output a list of handles of the objects it creates, you could delete them (keeping the rest of the figure intact) and replace them with the dipole a fraction of a second later. I am just working on bug 3096, where I needed to plot the layout in two different styles (selected versus non-selected channels), and where I had to update the figure without clf or cla. If you look at you will see that it now outputs "h" which is a list (vector) of all handles. That includes the symbols/points, boxes, and text. Getting all of those handles organized required the same solution that you seem to be looking for. for ft_plot_dipole that would correspond to returning the handles of the sphere and cylinder. it might be that h(1) = ft_plot_mesh(sphere,..) h(2) = ft_plot_mesh(cylinder,..) would work, but more robust would be h1 = ft_plot_mesh(sphere,..) h2 = ft_plot_mesh(cylinder,..) h = cat(2, h1(:)', h2(:)'); where it would also work if either one of the objects were to return multiple handles.

Diego Lozano Soldevilla - 2016-03-16 13:54:38 +0100

(In reply to Robert Oostenveld from comment #1) thanks Robert! I didn't know it was as easy as concatenate the handles... I tried copyobj.m and other more complicated stuff. You can find my changes in my github branch If you download the example data ( and you run the code below you'll see a beautiful dipole that rotates through the parietal cortex several alpha cycles ;) load dipolet1m.mat numcol = size(dipolet1m.dip,2); col1 = winter(numcol)'; col2 = hot(numcol)'; figure; ft_plot_slice(mris.anatomy, 'transform', mris.transform, 'location', [0.9381 -5.0290 2], 'orientation', [0 0 1], 'resolution', 0.1); ft_plot_slice(mris.anatomy, 'transform', mris.transform, 'location', [0.9381 -5.0290 2], 'orientation', [0 1 0], 'resolution', 0.1); ft_plot_slice(mris.anatomy, 'transform', mris.transform, 'location', [5 -5.0290 2], 'orientation', [1 0 0], 'resolution', 0.1); view([-27 78]); axis tight axis off for frame=1:numcol; h1 = ft_plot_dipole(dipolet1m.dip(:,frame).pos, dipolet1m.dip(:,frame).mom,'color',col1(:,frame)); axis tight; axis off; pause(0.05); set(h1,'Visible','off'); end If you agree with my changes, I ask the pull request

Robert Oostenveld - 2016-03-16 14:11:20 +0100

Looks good! Please do a PR.

Diego Lozano Soldevilla - 2016-03-16 15:11:15 +0100

(In reply to Robert Oostenveld from comment #3) pull request made!

Robert Oostenveld - 2016-03-16 15:37:20 +0100

I just merged

Robert Oostenveld - 2019-08-10 12:33:06 +0200

This closes a whole series of bugs that have been resolved (either FIXED/WONTFIX/INVALID) for quite some time. If you disagree, please file a new issue on