overlaying location map (coastline) on slice plots in MatLab? - matlab

I made plots of depth slices using function slice, with each slice showing earth's velocity distribution. I am having a hard time overlaying the location map (coastline) on the figure. Does anyone know if this is possible with MatLab? OR Can you overlay any x,y(and z) plot on slice image?

Thanks all! I figured it out. Had to import coastline data from some online database and used hold on/off to overlay, with plot3. My original plan of using the mapping tools on MatLab didn't work.

Related

How to plot two 2D histograms on the same 2D image?

I wonder if anyone can help me to plot two 2D histograms on the same plot.
I do some lifetime imaging and I want to reproduce my result as histograms (phasor plot method). I know how to plot a single 2D histogram, but not more, without removing the preceding one.
I am currently using the DIPimage toolbox, but I have seen that for plotting 2D histograms you can use as well the function 'ndhist'.
Please, find attached the picture. This is not obviously what I am after, as the background should be all blue and I would like to plot more 'clouds' over the universal circle.

Contour Plot of own coordinates with attached scalar

I have the following coordinate system of (x,y) and attached z value to each coordinate. I need to keep the coordinates the same without using some linear fit function to change it into a grid system of some sort. Is there a way i can create a contour of that data using that data only and not using griddata or something.
x=[0.2,0.2,0.05,1.1,0.8,0.9,1.8,1.9,2.05];
y=[0,1.1,2.1,0.1,1.1,2.2,0.15,1.1,2.05];
z=[0,1,0,0,2,1,0,1,0;];
plot(x,y, 'bo')
The reason is i have another model with 540 thousand coordinate points that is a weird shape and if i start using the other functions it loses its shape and goes rectangular.
One option you have is to use fitto create a fit surface of your data, and then directly plot it. This also has the advantage to give you extra parameters to control the interpolation between your points.
f=fit([x',y'],z','linearinterp')
plot(f,'Style','Contour')
Will create something like:
And
f=fit([x',y'],z','cubicinterp')
plot(f,'Style','Contour')
Will smooth the interpolation into:
Please look here for more information on fit and fit plotting options
https://www.mathworks.com/help/curvefit/fit.html#inputarg_fitType
https://www.mathworks.com/help/curvefit/plot.html

MATLAB: Digitizing a plot with multiple variables and implementing the data

I have 8 plots which I want to implement in my Matlab code. These plots originate from several research papers, hence, I need to digitize them first in order to be able to use them.
An example of a plot is shown below:
This is basically a surface plot with three different variables. I know how to digitize a regular plot with just X and Y coordinates. However, how would one digitize a graph like this? I am quite unsure, hence, the question.
Also, If I would be able to obtain the data from this plot. How would you be able to utilize it in your code? Maybe with some interpolation and extrapolation between the given data points?
Any tips regarding this topic are welcome.
Thanks in advance
Here is what I would suggest:
Read the image in Matlab using imread.
Manually find the pixel position of the left bottom corner and the upper right corner
Using these pixels values and the real numerical value, it is simple to determine the x and y value of every pixel. I suggest you use meshgrid.
Knowing that the curves are in black, then remove every non-black pixel from the image, which leaves you only with the curves and the numbers.
Then use the function bwareaopen to remove the small objects (the numbers). Don't forget to invert the image to remove the black instead of the white.
Finally, by using point #3 and the result of point #6, you can manually extract the data of the graph. It won't be easy, but it will be feasible.
You will need the data for the three variables in order to create a plot in Matlab, which you can get either from the previous research or by estimating and interpolating values from the plot. Once you get the data though, there are two functions that you can use to make surface plots, surface and surf, surf is pretty much the same as surface but includes shading.
For interpolation and extrapolation it sounds like you might want to check out 2D interpolation, interp2. The interp2 function can also do extrapolation as well.
You should read the documentation for these functions and then post back with specific problems if you have any.

Plot 3D surface that is not the graph of a function

I have a 3D data set of a surface that is not a function graph. The data is just a bunch of points in 3D, and the only thing I could think of was to try scatter3 in Matlab. Surf will not work since the surface is not a function graph.
Using scatter3 gave a not so ideal result since there is no perspective/shading of any sort.
Any thoughts? It does not have to be Matlab, but that is my go-to source for plotting.
To get an idea of the type of surface I have, consider the four images:
The first is a 3D contour plot, the second is a slice in a plane {z = 1.8} of the contour. My goal is to pick up all the red areas. I have a method to do this for each slice {z = k}. This is the 3rd plot, and I like what I see here a lot.
Iterating this over z give will give a surface, which is the 4th plot, which is a bit noisy (though I have ideas to reduce the noise...). If I plot just the black surface using scatter3 without the contour all I get is a black indistinguishable blob, but for every slice I get a smooth curve, and I have noticed that the curves vary pretty smoothly when I adjust z.
Some fine-tuning will give a much better 4th plot, but still, even if I get the 4th plot to have no noise at all, the result using scatter3 will be a black incomprehensible blob when plotted alone and not on top of the 3D contour. I would like to get a nice picture of the full surface that is not plotted on top of the 3D contour plot
In fact, just to compare and show how bad scatter3 is for surfaces, even if you had exact points on a sphere and used scatter3 the result would be a black blob, and wouldn't even look like a sphere
Can POV-Ray handle this? I've never used it...
If you have a triangulation of your points, you could consider using the trisurf function. I have used that before to generate closed surfaces that have no boundary (such as polyhedra and spheres). The downside is that you have to generate a triangulation of your points. This may not be ideal to your needs but it definitely an option.
EDIT: As #High Performance Mark suggests, you could try using delaunay to generate a triangulation in Matlab
just wanted to follow up on this question. A quick nice way to do this in Matlab is the following:
Consider the function d(x, y, z) defined as the minimum distance from (x, y, z) to your data set. Make sure d(x, y, z) is defined on some grid that contains the data set you're trying to plot.
Then use isosurface to plot a (some) countour(s) of d(x, y, z). For me plotting the contour 0.1 of d(x, y ,z) was enough: Matlab will plot a nice looking surface of all points within a distance 0.1 of the data set with good lighting and all.
In povray, a blob object could be used to display a very dense collection of points, if you make them centers of spheres.
http://www.povray.org/documentation/view/3.6.1/71/
If you want to be able to make slices of "space" and have them colored as per your data, then maybe the object pattern (based on a #declared blob object) might do the trick.
Povray also has a way to work with df3 files, which I've never worked with, but this user appears to have done something similar to your visualization.
http://paulbourke.net/miscellaneous/df3/

Plotting 3-D Matrix *values* in MATLAB

I have a 3D Matrix M(256x256x136) and each index(i,j,k) in M has a gray level value in it. I am interested in displaying M in some sort of a 3D plot in MATLAB, but am unable to do so. I cannot use plot3 because plot3 is for plotting points, not the values.
Thanks
If I understand your question correctly, you want to plot the 3D point cloud with i,j, and k as 3D coordinates and the gray level as the point value.
I would suggest using scatter3.
Sounds like you are looking for a volume renderer. For Matlab, you could try this one: Volume Render from Matlab Central
An isosurface plot might be useful as well.