add label to a contour when when multiples plots

Hello saviors,
so, I'm creating three contour from trhee matrix array on a single plot using hold on:
hold on
contour (muvec, muvec, spaln(:,:,1))
contour (muvec, muvec, spaln(:,:,2))
contour (muvec, muvec, spaln(:,:,3))
hold off
What I want is to label each contour with 1, 2, 3 for each matrix, so I can know which contour represent wich matrix array.
thank you all

 Accepted Answer

They appear to be plotted on the same set of coordinate matrices. One option is to use different line colours (and other variations) for each contour plot. You might also consider contour3, that will allow you to separate them vertically.

4 Comments

The idea of using different line colours seems the best one. I didn't want to do it, but if I can't just label each contour (not contour level), then I think I don't have any other option. (contour3 is discard for a more complicated reason). Thank you so much.
My pleasure.
I would use different colours, and label them in the legend.
As I mentioned, you can also plot the contour outputs as planes with constant offsets between the planes. You would have to get the (x,y) data from each call to the contour function for that, and add your own z vectors to to each one offset them.
Example Code —
M1 = peaks;
[X,Y] = meshgrid((1:49)*pi/25);
M2 = sin(X) .* cos(Y);
[H1,C1] = contour(M1);
L1 = C1.LevelList;
Lv1 = ismember(H1(1,:), L1);
H1p = H1;
H1p(:,Lv1) = NaN;
[H2,C2] = contour(M2);
L2 = C2.LevelList;
Lv2 = ismember(H2(1,:), L2);
H2p = H2;
H2p(:,Lv2) = NaN;
figure
plot3(H1p(1,:), H1p(2,:), ones(size(H1p(1,:)))*1)
hold on
plot3(H2p(1,:), H2p(2,:), ones(size(H2p(1,:)))*4)
hold off
grid on
zlim([0 5])
text([0; 0], [0; 0], [1; 4], {'Contour 1','Contour 2'})
Example Plot —
add label to a contour when when multiples plots - 2019 09 18.png
Experiment to get the result you want.
thank you, I didn't do it exactly like you, but your way help me a lot!
As always, my pleasure!

Sign in to comment.

More Answers (0)

Categories

Products

Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!