I have created a smooth color gradient 2-D contour plot with existing compiled data in Matlab. I have an x-axis, y-axis, and z-data contour plotted as a colormap. My goal is to plot a 2-D curve onto the colormap, representing a single z-data value, but I don't know how. Does anyone know how to plot a 2-D curve onto a 3-D colormap? I have provided a link to the current colormap onto which I wish to plot a single z-value as a curve. Existing colormap
x = 0.05:0.05:1;
y = 0.0:0.05:1;
[X, Y] = meshgrid(x, y);
Z = [data]
contourf(X, Y, Z);
pcolor(X, Y, Z);
shading interp
title()
xlabel()
ylabel()
colorbar
Thanks to @Cris Luengo for his comments directing me to
contourc
. Notice thatcontourc
returns the isolines. According to the documentation,which implies we can identify specific values for the isolines (values of
Z
) withv = [.5 0.75 .85];
and then just use a loop to iteratively get the info needed using
which allows us to pass the info to
plot(...)
in the code below.Old but works: Will delete once above answer finalized
Disclaimer: There may be an easier way to do this. See note at bottom.
The
plot
command can overlay anything you want on top. Or you can usecontourf
and specify the contours marked, including highlighting individual contours. I've illustrated two approaches—I believe the one you're looking for useshold on; plot(...)
as demonstrated below & with the left image.In the left figure, you'll see I used logical indexing.
The success of this approach greatly depends on how fine the mesh is on
Z
and on the required tolerance (tol
). If the Z-mesh is limited by data, then you'll have to adjust the tolerance and tune to your liking or to the limit of your data. I simply adjusted until I got the figure below and didn't tinker further.Edit:
For future visitors, if the relationship between
X
,Y
, andZ
is known, e.g.sqrt(X.^3 + Y) = Z
, then drawing a single curve for a particularZ
value may be extracted from that relationship (equation) directly by solving the equation. If it is based on data instead of an analytical formula, then that may be more difficult and the approach above may be easier (thanks to @Cris Luengo for pointing this out in the comments).