I tried to fit a HeatMap as a subplot of a plot. However it seems they are not compatible. Every time using a HeatMap function, it seems it will always open a HeatMap 'canvas'. If save the result of HeatMap as a object and use plot or view to put it into a figure, it always open a new figure window rather than plot on the existing one, even with the hold on; command. Is there a way to make the HeatMap as one of the subplots?
A heatmap example code:
y = [1,2,3,4;5,6,7,8;4,3,2,1;8,7,6,5];
obj = HeatMap(y,'Symmetric','false','colormap','jet'); %this will generate a HeatMap canvas
plot(HeatMap); %this will display or render the heatmap object into a figure window
It seems I should use imagesc rather than HeatMap function as imagesc is more compatible. By using imagesc to plot the matrix, I can easily set the heatmap as a subplot.
Related
I am a bit struggling with my polar plot. I am playing with strikes and dips, and for each pair of those, an "intensity". I'd like to plot this surface/contourf/whatever function on my polarplot. I cannot find the handle to do so. Dpp2 contains the intensity value for a given theta and rho/ strike and dip.
xTmp = (0:4:360);
yTmp = (0:22.5:90);
[strike,dip]= meshgrid(deg2rad(xTmp),deg2rad(yTmp));
dip2 = rad2deg(dip);
strike2 =rad2deg(strike);
figure('name', 'COLD');
polarplot([0 360],[0 90]);
s = surf(strike2, dip2, DPp2);
polarplot(s);
colormap
I've tried something like that, which obviously doesn't work.
cheers,
Flo
As far as I know there is no way of creating a surface plot directly in a polarplot.
One workaround is to manually create your polar axis plot. You can find an example here.
Another workaround would be to use
polarscatter to create a scatter plot (which looks simmilar in case you have a tight grid) Have a look at this.
Because you mentioned the handle: In case you want a handle to the axes have a look at polaraxes from here.
The polar scatter wasn't working, so I tried another function, which seems to work according to this page: https://fr.mathworks.com/matlabcentral/answers/95796-how-do-i-create-a-contour-plot-in-polar-coordinates
I am note quite there yet, the contour map isn't "wrapped" around my polar plot, but so far it's compiling. If anyone has an idea on how to superimpose the contour map onto the polar plot ?
dip2 = rad2deg(dip);
strike2 =rad2deg(strike);
h = polar([0 360],[0 90]);
hold on;
contourf(strike2,dip2,DPp2);
% Hide the POLAR function data and leave annotations
set(h,'Visible','off')
% Turn off axes and set square aspect ratio
axis off
axis image
I have plotted to vectors against each other, and they are already logarithmic and everything is fine with that. But now that I have my plot i want the grid to be logarithmic. I write "grid on" in my code, and I think there should be a way to do this in the plot, but I can't remember how. How do I make the grid logarithmic?
If you use loglog, semilogx or semilogy instead of plot, the grid will automatically be on a log scale for the corresponding axes when using grid on.
If you have already plotted the axes, you can execute the following on the command line:
set(gca,'yscale','log') %# to set the y-axis to logarithmic
set(gca,'xscale','log') %# to set the x-axis to logarithmic
Have a look at axes properties to find out what else you can modify.
I have got a data of size 13558x100 and I am trying to plot it. For 2D, I could use:
plot(X(:,1), X(:,2))
How can I plot this big data? Can I just use surf to visualize the data or is there any other way?
As others have mentioned imagesc is the better way to go about this. It allows you to see a field of 2D data without a 3D plot using colour mapping. The toy example code is here.
Y = randn(13558,100);
figure; imagesc( Y );
This code generates the image as follows.
Furthermore, you can use the function colorbar to get a bar legend for your data.
colorbar;
After using the colorbar function, it generates the figure below.
I have plotted to vectors against each other, and they are already logarithmic and everything is fine with that. But now that I have my plot i want the grid to be logarithmic. I write "grid on" in my code, and I think there should be a way to do this in the plot, but I can't remember how. How do I make the grid logarithmic?
If you use loglog, semilogx or semilogy instead of plot, the grid will automatically be on a log scale for the corresponding axes when using grid on.
If you have already plotted the axes, you can execute the following on the command line:
set(gca,'yscale','log') %# to set the y-axis to logarithmic
set(gca,'xscale','log') %# to set the x-axis to logarithmic
Have a look at axes properties to find out what else you can modify.
I want to select data using a polygonal shape. I understand roipoly does that for 'images'. is there something like this for scatter plots?
You can use data brushing to mark data on a scatter plot then extract it to the workspace. Look for the little brush symbol at the top of a figure window.
See Marking up graphs with Data Brushing from Matlab, and Accessing plot brushed data from the very useful Undocumented Matlab.
If you want to draw a complex polygon, you can use impoly and inpoly:
X = rand(200, 2);
scatter(X(:,1), X(:,2));
h = impoly();
% now you go and position the polygon, control returns once you've 'finsished' with it '
nodes = getPosition(h);
selected_indices = inpoly(X, nodes);