Matlab: Boxplot with individual value markers - matlab

How can I produce boxplots that also show all the values by themselves?
e.g. like here in subfigure A and B of this:
I can just plot them after a "hold on" but then they are not nicely arranged according to the x-axis as in the example above. Isn't there a matlab standard function for that?

Related

How to plot Tsne in matlab using specific color

I am trying to plot the result of Tsne using gscatter in Matlab.
I want to use specific color for training and other color for Anchors
Y=tsne(xtrain; xAnxhors]);
gscatter(Y(:,1),Y(:,2));
That is the code that I used but I got the figure in one color only so I want to show the diffrence of colors between xtrain and xAnchors
The function gscatter allows you to specify two more arguments. With the first one you can already define groups (a vector that indicates for each point what group it belongs to) which will automatically assign different colours to different groups. The second argument allows for an even more fine grained control about the actual choice of colours. For reference an example from the documentation:
Plot the Displacement values on the x-axis and the Horsepower values on the y-axis. gscatter uses the variable names as the default labels for the axes. Group the data points by Model_Year.
load carsmall
gscatter(Displacement,Horsepower,Model_Year)

Matlab - Error bars added to column plot instead of regular line plot, and stacked 2x2

I would like to create a 2x2 plot with error bars, where each mean is represented by a column rather than by a marker (data point), something like this:
The errorbar function in Matlab seems to not have the option to make columns instead of simple markers, and also no option to stack the four entities as 2x2, instead giving me something that looks like this:
You can create a bar plot with the function bar(Y), which will draw one bar for each element in Y. So if your data has 2 columns, the plot will be 2x2. You can then add errorbars with the errorbar function, and specify the linespec 'x' per example, to avoid the lines between the markers.
figure
hold on
bar(data)
errorbar(data,'x')
hold off

how to write some text in the plot in matlab

I wrote the following code in matlab for plotting a graph. I have three curves in the same plot. I want to mention the particular class to each curve to which it belongs.How can I do it using same code that i wrote. Code is:
plot(mm,q1(1,:),'b')
hold on
plot(mm,q1(2,:),'g')
plot(mm,q1(3,:),'r')
plot(mm,q1(4,:),'m')
xlabel('time(yr)')
ylabel('probability')
hold off
I want to write 'M1 to M2'in plot corresponding to graph for plot(mm,q1(1,:),'b'). Similarily for other plots 'M1 to M2' , 'M1 to M3' ,'M1 to M4' respectively.
You can use legend as follows:
legend('M1 to M2','M1 to M3','M1 to M4');
This allows you to label curves.

How to define Matlab Bar3 DisplayName for individual surface objects

I have a series of histograms being plotted along side each other in a bar3 plot. I'd like to take advantage of the plot browser to turn on and off various histograms so I can do side by side comparisons. You can see from the properties Inspector that I've altered the display name for one such surface, the third, that is being updated in the legend but not in the property browser.
There's also a misregistration of the colors you see in the legend to that of the actual plot. The legend is accurate only when I have all surfaces checked for display.
I'm using MATLAB Version 7.13.0.564 (R2011b)
Thanks for helping
Toggle the legend off and on with legend('off') followed by legend('show'). Try also legend('toggle').

surf() in Matlab showing only two colors instead of multiple colors

I am using the following lines of code to plot:
nthTheta=1;
gammaSurf=reshape(gamma(:,nthTheta,:),size(gamma,1),size(gamma,3));
figure
[spatial_lag,temporal_lag]=meshgrid(distance,4:4:12);
surf(gammaSurf,spatial_lag',temporal_lag')
colorbar
xlabel('Spatial Lag','Fontweight','Bold')
ylabel('Temporal Lag','Fontweight','Bold')
zlabel('\gamma (h,t)','Fontweight','Bold')
title('Spatiotemporal Empirical Variogram','Fontweight','Bold')
The gammaSurf matrix has following values which shows its values are changing:
I get the following plot with only two colors instead of multiple variation in colors:
Am I doing something wrong because of which I am not getting a plot with multiple color variation which I expect? Thanks!
Set the shading to be interpolated:
shading(gca,'interp');
should do the trick.
Actually, it looks like you've got the arguments to surf in the wrong order. If you want the z-axis to apply to the gammasurf values, that needs to be the third argument.
surf(spatial_lag',temporal_lag',gammasurf);
One last suggestion: If you indeed did mean for gammasurf to be the x-values but you wanted those to be what define the color, use that as the 4th argument (C):
surf(gammasurf,spatial_lag',temporal_lag',gammasurf);
Now the surface will be oriented like in the image, but with colors varying with the x-value rather than the z-value.