Filling area of multiple contour plots that satisfies a condition in MATLAB - matlab

I have a 3D data, the x and y axis are angles and the Z axis is output. so the data is like this: [angle1 x angle2 x Z] ... I have multiple Z values at different conditions as well. Let's assume different Z values for 10 different conditions.
I want to plot a 3D contour of all the Z values overlaid on top of each other and at the same time fill the areas of each contour where Z<=-1 with a desired color ... How is that possible in MATLAB?
I found a way to overlay all the Z values on top of each other using a single color and contour command but I cannot find any way to fill the areas of Z<=-1 ... I realized that in contour command, MATLAB actually fill the whole graph with colors, so "hold on" command does not work here!
Here is an example image I want to create
Below is the example I could create but I cannot create the colored plot

Related

Matlab: How to plot coordinate locations using x markers in a contour map?

I need to plot the locations of 3 treasures on a contour map.The coordinates are in a matrix (3x2) called "treasures", the first column contains the y coordinates, and the second column the x coordinates.
Using an X marker I was asked to plot the treasures locations using a marker size of 15, a line width of 4 and a red color.
How could I do that? the image should look like this
It looks like you need to read a basic tutorial on matlab first before you take on this project.
plotting scattered points can be done in matlab using the command plot. Assuming your treasure locations is x and y (both can be a vector for multiple points), you can plot those using
plot(x,y,'rx','markersize',15)

How to plot overlapping images with matlab

I have several dataset matrices x, y, andz, where z contains values at the positions x,y showing shifted (overlapping) parts of the same picture. x and y are rectangularly centered around different center positions for each dataset.
How can I combine the data in one plot using pcolor or similar? Note that it should be a rectangular plot in the end, but that not all data points are given due to the shift.
I now solved my own question by using the command hold on, which makes it possible to plot several times into the same figure. You just have to run it in between two plot commands.

Surface plot on top of colour image (x-y plane)

I guess, I've got an colormap issue with Matlab2013. I plot a 3d surface plot with colormap hot and I would like to have in the same plot an bitmap (8bit colour image) on the x-y plane. Plotting both separately from each other works fine but as soon as I plot them in one figure the first surface plot is only black. I guess it is because the RGB image on the x-y plane uses a different colour map. Is there an option in Matlab to plot two different type of images in the same plot?
surf(X,Y,density,'FaceColor','texturemap','Edgecolor','none')
colormap hot
...
%// define the location of the bitmap
xImage = [miX maX; miX maX]; %// The y data for the image corners
yImage = [miY miY; maY maY]; %// The x data for the image corners
zImage = [zDist zDist; zDist zDist]; %// The z data for the image corners
surf(xImage,yImage,zImage,... %// Plot the surface
'CData',RGBImage,...
'FaceColor','texturemap');
Thanks!
Durin
I think this is an issue with the relative scaling of density and zImage. I can replicate this by doing the following:
1) Plot a surf where the third input is n x m which is scaled like some real data (-0.2 to +0.2, for example). This responds to changes in colormap as you'd expect.
2) After hold on, plot another surf where the third input is n x m x 3, like a RGB image, double values scaled between 0 and 1.
This causes the first image to go "dark" (or whatever the lowest color in that particular colormap is). The issue is that they share their CLim, being in the same axis, although the RGBImage doesn't, in fact, reference the colormap.
This is "fixable" by scaling/normalising the first plot (your density values) to be between 0 and 1 (in this case) - although this quick fix is going to give you issues if you then want to add a colorbar. Alternatively, first grab the "CLim" from your axis after plotting the first surf:
trueC = get(gca,'CLim');
Then set it back after you plot the image:
set(gca,'CLim',trueC)

How to set an arbitrary direction on a contour plot to perform operation in Matlab

I am looking for help for my particular problem.
I have a contour plot created from XYZ data. This plot contains 2 broad peaks with one more intense than the other.
When the most intense peak is aligned with the Y axis, I can perform a fitting of every YZ curve at each X values. I usually do a gaussian fit to plot the peak center on the same graph.
In some cases I need to perform the same fitting but no along the Y axis direction (in this case I just plot YZ scan at every different X values) but along another arbitrary direction.
For the moment the only way I found is the following:
-plot the contour plot and find for the position of the most intense peak
-if the position is not aligned with the Y axis, then rotate all the datas and plot again the contour
-perform the YZ gaussian fit for every X value
- Rotate the resulting XY position to go back to the original plot
-plot the XY position as a line on the original contour plot
this is quite long and requires a lot of memory. i would like ot know if there is a more elegant/faster way.
Thanks for your help
David
I take it you want to extract data from the (x,y,z) data along some arbitrary line in order to make a fit. A contour plot will show only part of the data, the full z(x,y) data can be shown with imagesc etc. Say you want the data along line defined by two points (x1,y1) -> (x2,y2). According to the eq of the line, the line y=a*x+b the slope a is (y2-y1)/(x2-x1) and b=y1-a*x1. For example, I'll select (x,y) coordinates in the following contour:
Create data and end points:
m=peaks(100);
x1=11 ; x2=97;
y1=66; y2=40;
Thus the line parameters are:
a=(y2-y1)/(x2-x1);
b=y1-a*x1;
and the line is:
x=x1:x2;
y=round(a*x+b);
select the proper (x,y) elements using linear indexing:
ind=sub2ind(size(m),y,x)
plot:
subplot(2,1,1)
contour(m,10); hold on
line([x1 x2],[y1 y2],'Color',[1 0 0]);
subplot(2,1,2)
plot(m(ind))
You can now use vec=m(ind) to fit your function.

turn scatter plot into area plot

I have a 2D scatter plot in MATLAB. Is it possible to interpolate the scatter plot to create an area plot?
If you're simply trying to draw one large filled polygon around your entire set of scattered points, you can use the function CONVHULL to find the convex hull containing your points and the function PATCH to display the convex hull:
x = rand(1,20); %# 20 random x values
y = rand(1,20); %# 20 random y values
hullPoints = convhull(x,y); %# Find the points defining the convex hull
patch(x(hullPoints),y(hullPoints),'r'); %# Plot the convex hull in red
hold on; %# Add to the existing plot
scatter(x,y); %# Plot your scattered points (for comparison)
And here's the resulting figure:
Scatter is generally used to represent data where you can't use a line graph, i.e., where each x might have many different y values, so you can't convert directly to an area graph--it would be meaningless. If your data actually is representable as a line graph, then pass it to area directly.
So I'm not quite sure what you want, but here are some possibilities:
You could create a Voronoi diagram based on your points. This will show a region near your points showing which points are closer to a specific point: voronoi(x,y), or see the help.
You could bucket or quantize your data somehow, making it fit into a grid, and then plot the grid. This could also be considered a histogram, so read up on that.
You could just use larger scatter markers (scatter(x,y,scale) where scale is the same dimensions as x and y).