I am trying to create histograms in a loop. I am creating two figures and want a suptitle above them, but when I do that the title of the subplots doesn't work anymore . This is my code
suptitle('Observation')
for i=1:c:b
i
MagObs1=[];
subplot(b,1,i);
MagObs1=MagObs(:,i);%0 and 1s
minMagObs1=min(MagObs1);
MagObs2=MagObs1(MagObs1>0.001);
h1=histogram(MagObs2,NumberBins,'Normalization','probability');
title([num2str(DepthObs(i)),'m']);
h1.BinLimits=[bottomVel topVel];
xlabel('Current speed (m/s)');
ylabel('Frequency');
end
figure(2);% clf;
suptitle('Model')
for i=1:c:b
subplot(b,1,i);
h2=histogram(MagMatrixH1(i,:),NumberBins,'Normalization','probability')
title([num2str(DepthObs(i)),'m'])
h2.BinLimits=[bottomVel topVel]
xlabel('Current speed (m/s)')
ylabel('Frequency')
end
and this is the error I get
Error using axes
Invalid axes handle
Error in suptitle (line 98)
axes(haold);
Error in Histogram (line 118)
suptitle('Observation')
This is my output. Normally, every figure has multiple histograms underneath each other, but for this example I only show one.
As you can see in the second picture. "Im" should be '300m', could you help me fix this subplots title?
In the (very little) documentation that suptitle has, it says:
"Use this function after all subplot commands."
Try adding it in the end of your plotting
Related
I am plotting two plotpc charts (i want to see decision boundaries from perceptron and from Bayesian net) and I need them to have different color.
plotpv(P,T);
hold all;
plotpc(net.IW{1,1},0,'r');
plotpc([w1(maxind(1)), w2(maxind(2))],0,'g');
title('Decision boundaries');
However all my trials ended up with failure and I always get same colors like this:
Thank you for help.
You need to assign the output of plotpc (line handle) to some variable, which you can then use to alter line appearance, e.g.
hPlot = plotpc(net.IW{1,1},0);
set(hPlot, 'Color', 'r');
Also, I don't think plotpc accepts a color as a third argument - you should get a warning when you do that.
I am trying to add error bars to a line plot, using MATLAB R2015a.
I've gotten so far that dots are plotted as error bars - not lines that go up and down from the points.
YLim is 0 to 100.
One of the standard deviations (length of error line) is 10, so it is impossible for it to be plotted as only a dot.
This lead me to think that something is bugged in my errorbar() function.
Copying the following code from Matlab's errorbar help:
x = 0:pi/10:pi;
y = sin(x);
e = std(y)*ones(size(x));
figure
errorbar(x,y,e)
produces an empty figure, not a sine wave with error bars as in the help file...
Any idea what might be going on?
First post here.
I have a bunch of xy data (actually lats and longs), plotted the lines successfully with a scalar value for each line. Scalar values run between 0 and 0.5'ish. Created a colormap and ran it between 0 and 1, based on the native 'autumn' map. I got this far from a couple of other posts, not exactly what I was trying to do but managed to get close using the information provided for others. Issue now is that the relative colorbar that comes up in the plot is all one color??
Here is my script:
figure
% Define colormatrix
cols=flipud(autumn(1001));
% Interpolate the COL matrix to get colors for the data
tcols=interp1(0:0.001:1,cols,probS);
set(gcf,'DefaultAxesColorOrder',tcols);
colormap(tcols);
plot(xx,yy);
caxis([0,1])
c=colorbar;
It tried to attach an image to show what I mean but was denied as a first time user.
The funny thing is, when I run the same script but substitute the xy and the scalar value (probS) for the randomly generated numbers the colorbar behaves, e.g.
close all;clear all
xx=rand(75,25)*10;
yy=rand(75,25)*10;
probS=sort(rand(75,1));
figure
% Define colormatrix
cols=flipud(autumn(1001));
% Interpolate the COL matrix to get colors for the data
tcols=interp1(0:0.001:1,cols,probS);
set(gcf,'DefaultAxesColorOrder',tcols);
colormap(tcols);
plot(xx,yy);
caxis([0,1])
c=colorbar;
any advice or ideas would be most appreciated.
I want to plot a circle on a map figure.
I tried the axesm function and then the scircleg but although the mouse clicks worked the coordinates don’t pass and the following message appears
Attempt to execute SCRIPT message as a function:
c:\did\zmap\zmap\src\message.m
Error in scircleg (line 124)
warning(message('map:scircleg:emptyLATPTS'))
Any help is welcome
Thank you in advance
if you need to add circles on a plot for indicating something on an existing figure, you can use:
hold on
plot(100,200,'o');
This adds a small circle at point (100,200).
I'm trying to create a sliding window (with a slider) to view multiple subplots each of which is a long time series.
S=['set(gca,''xlim'',get(gcbo,''value'')+[0 ' num2str(chunkDuration) '])'];
h=uicontrol('style','slider','units','normalized','position',Newpos,...
'callback',S,'min',0,'max',xmax-chunkDuration);
As written, this only causes the bottom plot to move. I understand that's because I set gca. However, changing gcf to gca won't help because that would try to set the xlim of figure instead of its children.
When I try
kids = get(gcf,'Children')
S=['set(kids,''xlim'',get(gcbo,''value'')+[0 ' num2str(chunkDuration) '])'];
I get the error:
??? Undefined function or variable 'kids'.
??? Error while evaluating uicontrol Callback
So, why doesn't the above work?
Even after a substantial change in approach, the problems remain.
Somewhere in your code you try to use a variable named subplot_handles. The error arises because this variable is undefined at the time you try to use it.
Update:
Is there a reason why you are saving your set commands as Strings? I suspect that its completely un-needed.
When you create your subplots try storing the handles to the axes created by the subplot objects.
ax(1) = subplot(311);
ax(2) = subplot(312);
ax(3) = subplot(313);
Later on you can set the limits for all subplots using:
set(ax, 'XLim', get(gcbo,'value') + [0 num2str(chunkDuration)] );