Undo Markers in reopened fig fieldtrip - matlab

some time ago I have done topoplots of my MEG Data using ft_topoplotTFR and saved them as fig files. I have set the cfg.marker = 'on'.
Now I need the files but without the markers, because they just make the picture black and i cannot identify a lot. The markers are the Sensors. See in this picture:
TopoplotTFR
The black little circles that cover the surface are the markers I am talking about.
ft_topoplotTFR belongs to the fieldtrip toolbox and makes topoplots of Brain Data.
http://www.fieldtriptoolbox.org/reference/ft_topoplottfr
Can I somehow change the marker settings in the figure if i just have the fig file?

While we have no idea what ft_topoplotTFR is, the answer is going to follow more or less the same general steps: Load the figure, identify the plot objects, and modify their properties.
For example, we can generate a busy sample plot:
x = 0:0.05:10;
y1 = 5*rand(size(x));
y2 = 5*abs(sin(x));
plot(x, y1, '-d', x, y2, '-p');
savefig('test.fig');
close
We can then use openfig to load the figure so we can access the plotted data:
myfig = openfig('test.fig');
% Child of a basic figure window with a plot is the axes object
myaxes = myfig.Children;
% Child(ren) of a generic axes with plotted data are the plot object(s)
myls = myaxes.Children;
set(myls, 'Marker', 'none'); % Turn off markers
Which gives us:

Related

How to update a scatter3 plot (in a loop) in Matlab

Quite a simple question but just couldn't find the answer online... I want to visualise a point cloud gathered from a lidar. I can plot the individual frames but wanted to loop them to create a "animation". I know how to do it for normal plots with drawnow but can't get it working with a scatter3. If I simply call scatter3 again like I have done in the commented code then the frame that I am viewing in the scatter plot jumps around with every update (Very uncomfortable). How do i get the scatter3 plot to update to the new points without changing the UI of the scatter ie. Still be able to pan and zoom around the visualised point cloud while it loops through.
EDIT: The file is a rosbag file, I cannot attach it because it is 170MB. The problem doesn't happen when using scatter3 in a loop with a normal array seems to be something with using scatter3 to call a PointCloud2 type file using frame = readMessages(rawBag, i).
EDIT: The problem does not seem to be with the axis limits but rather with the view of the axis within the figure window. When the scatter is initialised it is viewed with the positive x to the right side, positive y out of the screen and positive z upwards, as shown in view 1. Then after a short while it jumps to the second view, where the axis have changed, positive x is now out of the screen, positive y to the right and positive z upwards (both views shown in figures). This makes it not possible to view in a loop as it is constantly switching. So basically how to update the plot without calling scatter3(pointCloudData)?
rawBag = rosbag('jackwalking.bag');
frame = readMessages(rawBag, 1);
scatter3(frame{1});
hold on
for i = 1:length(readMessages(rawBag))
disp(i)
frame = readMessages(rawBag, i);
% UPDATE the 3D Scatter %
% drawnow does not work?
% Currently using:
scatter3(frame{1})
pause(.01)
end
The trick is to not use functions such as scatter or plot in an animation, but instead modify the data in the plot that is already there. These functions always reset axes properties, which is why you see the view reset. When modifying the existing plot, the axes are not affected.
The function scatter3 (as do all plotting functions) returns a handle to the graphics object that renders the plot. In the case of scatter3, this handle has three properties of interest here: XData, YData, and ZData. You can update these properties to change the location of the points:
N = 100;
data = randn(N,3) * 40;
h = scatter3(data(:,1),data(:,2),data(:,3));
for ii = 1:500
data = data + randn(N,3);
set(h,'XData',data(:,1),'YData',data(:,2),'ZData',data(:,3));
drawnow
pause(1/5)
end
The new data can be totally different too, it doesn't even need to contain the same number of points.
But when modifying these three properties, you will see the XLim, YLim and ZLim properties of the axes change. That is, the axes will rescale to accommodate all the data. If you need to prevent this, set the axes' XLimMode, YLimMode and ZLimMode to 'manual':
set(gca,'XLimMode','manual','YLimMode','manual','ZLimMode','manual')
When manually setting the limits, the limit mode is always set to manual.
As far as I understood what you describe as "plots jumpying around", the reason for this are the automatically adjusted x,y,z limits of the scatter3 plot. You can change the XLimMode, YLimMode, ZLimMode behaviour to manual to force the axis to stay fixed. You have to provide initial axes limits, though.
% Mock data, since you haven't provided a data sample
x = randn(200,50);
y = randn(200,50);
z = randn(200,50);
% Plot first frame before loop
HS = scatter3(x(:,1), y(:,1), z(:,1));
hold on
% Provide initial axes limits (adjust to your data)
xlim([-5,5])
ylim([-5,5])
zlim([-5,5])
% Set 'LimModes' to 'manual' to prevent auto resaling of the plot
set(gca, 'XLimMode', 'manual', 'YLimMode', 'manual', 'ZLimMode', 'manual')
for i=2:len(x,2)
scatter3(x(:,i), y(:,i), z(:,i))
pause(1)
end
This yields an "animation" of plots, where you can pan and zoom into the data while continuous points are added in the loop

Plot within a plot in MATLAB

I am trying to create a smaller plot within a plot in MATLAB, for example like the image of this MATLAB File Exchange Upload.
There, two figures are created and then both of them are plotted in one figure.
My problem however is that I already have two MATLAB figures from earlier simulations and I need to embed one figure into the other one, i.e., one would be small and the other plot would be big but in the same graph. Could someone suggest an easy way to do this?
This can be done using the copyobj function. You'll need to copy the Axes object from one figure to the other:
f(1) = openfig('fig1.fig');
f(2) = openfig('fig2.fig');
ax(1) = get(f(1),'CurrentAxes'); % Save first axes handle
ax(2) = copyobj(get(f(2),'CurrentAxes'),f(1)); % Copy axes and save handle
Then you can move and resize both axes as you like, e.g.
set(ax(2),'Position', [0.6, 0.6, 0.2, 0.2]);

How to specify the axis size when plotting figures in Matlab?

Suppose that I have 2 figures in MATLAB both of which plot data of size (512x512), however one figure is being plotted by an external program which is sets the axis parameters. The other is being plotted by me (using imagesc). Currently the figures, or rather, the axes are different sizes and my question is, how do I make them equal?.
The reason for my question, is that I would like to export them to pdf format for inclusion in a latex document, and I would like to have them be the same size without further processing.
Thanks in Advance, N
Edit: link to figures
figure 1: (big)
link to smaller figure (i.e. the one whose properties I would like to copy and apply to figure 1)
For this purpose use linkaxes():
% Load some data included with MATLAB
load clown
% Plot a histogram in the first subplot
figure
ax(1) = subplot(211);
hist(X(:),100)
% Create second subplot
ax(2) = subplot(212);
Now link the axes of the two subplots:
linkaxes(ax)
By plotting on the second subplot, the first one will adapt
imagesc(X)
First, you have the following:
Then:
Extending the example to images only:
load clown
figure
imagesc(X)
h(1) = gca;
I = imread('eight.tif');
figure
imagesc(I)
h(2) = gca;
Note that the configurations of the the first handle prevail:
linkaxes(h)
1.Get the handle of your figure and the axes, like this:
%perhaps the easiest way, if you have just this one figure:
myFigHandle=gcf;
myAxHandle=gca;
%if not possible, you have to search for the handles:
myFigHandle=findobj('PropertyName',PropertyValue,...)
%you have to know some property to identify it of course...
%same for the axes!
2.Set the properties, like this:
%set units to pixels (or whatever you prefer to make it easier to compare to the other plot)
set(myFigHandle, 'Units','pixels')
set(myAxHandle, 'Units','pixels')
%set the size:
set(myFigHandle,'Position',[x_0 y_0 width height]) %coordinates on screen!
%set the size of the axes:
set(myAxHandle,'Position',[x_0 y_0 width height]) %coordinates within the figure!
Ok, based on the answer of #Lucius Domitius Ahenoba here is what I came up with:
hgload('fig1.fig'); % figure whose axis properties I would like to copy
hgload('fig2.fig');
figHandles = get(0,'Children');
figHandles = sort(figHandles,1);
ax(1) = findobj(figHandles(1),'type','axes','-not','Tag','legend','-not','Tag','Colorbar');
ax(2) = findobj(figHandles(2),'type','axes','-not','Tag','legend','-not','Tag','Colorbar');
screen_pos1 = get(figHandles(1),'Position');
axis_pos1 = get(ax(1),'Position');
set(figHandles(2),'Position',screen_pos1);
set(ax(2),'Position',axis_pos1);
This is the 'before' result:
and this is the 'after' result:
Almost correct, except that the aspect ratios are still off. Does anybody know how to equalize everything related to the axes? (I realize that I'm not supposed to ask questions when posting answers, however adding the above as a comment was proving a little unwieldy!)

Plot data behind 2D plot in Matlab

I have a fairly complex plotting problem that i thought it would be interesting to get a solution to. Say i have two plots, number 1:
This plot was created using plotyy.
And number 2:
This plot was created using plot3(x, y, z, '.')
Now, the complex part is i want to take plot number 2, watermark it and put it behind plot number 1. Which would result in something like this:
Effectively what i want to show is that plot 1 is made from data that looks like plot 2. Now i haven't been able to find how to do this so it may not even be possible, but if it can be done then it would be a great tutorial to have on stack overflow!
You can do this but it will take some work to get the axes formatted so they look nice.
What you need to do is put one axes object on top of another axes; however, to prevent the top axes from occluding the bottom one you need to set the 'Color' property of the top axes object to 'none'.
Here is an example script that generates something similar to what you are looking for
f = figure;
axes();
x = rand(100,3)*3 + 3;
plot3(x(:,1), x(:,2), x(:,3),'.');
axes('Color', 'none');
x = -5:5;
y = x.^2;
line(x,y, 'Color', 'r', 'LineWidth', 2);
Here is the resulting figure:
If you don't like how this works out you can try to project your 3D data into 2D and then draw that projection as an image behind your lines. Here is a link to a discussion about how you might go about creating the 2D projection.

How to plot graphs above each other in Matlab?

I want to plot two (or more) graphs in Matlab. I want them to be aligned one above the second one above the third and so on. However subplot is not the case for me. I also don't want them both to be on the same graph in different colors, just to be one above the other. Is it possible? I'm searching for such a command but without any success.
Thanks in advance for hints!
If what you mean by "one above the other" is one "on top of another" then I think what You need to use is the axes command. Having said that, in order to have your plot be readable, I think more than two scales in the same plot makes it pretty hard to read.
This Matlab's help page shows you how to do it, the gist of it is shown in the following script:
y2 = 1000.*rand(100,1);
x2 = 0:99;
% Plot the first data set
hl1 = line(x1,y1,'Color','r');
% Get the axes and configure it
ax1 = gca;
set(ax1,'XColor','r','YColor','r')
%Create the new axes
ax2 = axes('Position',get(ax1,'Position'),...
'XAxisLocation','top',...
'YAxisLocation','right',...
'Color','none',...
'XColor','k','YColor','k');
% Plot the second data set with the new axes
hl2 = line(x2,y2,'Color','k','Parent',ax2);
The above script creates the following plot with one set of axes in red and another in black.
Hope this helps.