Clear Filters
Clear Filters

adding lines to a contour plot with labels

64 views (last 30 days)
HC98
HC98 on 5 Jul 2023
Edited: KALYAN ACHARJYA on 5 Jul 2023
I want to produce something like this
But I'm not sure how- how might one add lines and labels to contor plots?
  1 Comment
Aakash
Aakash on 5 Jul 2023
Hi,
What I understand from your question is that you want to add line plots in a contour plot, for that:
  1. Use the contour or contourf function to create the contour plot of your data.
  2. To add lines to the contour plot, you can use the hold on command to enable multiple plot overlays. Then, use the plot function to draw the desired lines. (do this for each line)
for example:
hold on;
x_line = [x1, x2]; % x-coordinates of the line endpoints
y_line = [y1, y2]; % y-coordinates of the line endpoints
plot(x_line, y_line, '--');
3. To add labels to the contour plot, you can use the text function to place text at specific coordinates on the plot.
for example:
x_label = x_coordinate; % x-coordinate of the label
y_label = y_coordinate; % y-coordinate of the label
label_text = 'a'; % Text for the label
text(x_label, y_label, label_text, 'FontSize', 12, 'Color', 'black');

Sign in to comment.

Answers (1)

KALYAN ACHARJYA
KALYAN ACHARJYA on 5 Jul 2023
Edited: KALYAN ACHARJYA on 5 Jul 2023
x1 = -10:0;
y1=10:-1:0;
x2 = 0:10;
y2=0:10;
x3=zeros*(0:10);
y3=0:10;
plot(x1,y1,x2,y2,x3,y3,'--');
text(x1(round(length(x1)/2)),y1(round(length(y1)/2))+1,'a');
text(x2(round(length(x2)/2)),y2(round(length(y2)/2))+1,'c');
text(x3(round(length(x3)/2)),y3(round(length(y3)/2))+1,'b');
You can also create the corresponding function equation as per requirement since it have simple linear relationship.

Categories

Find more on Contour Plots in Help Center and File Exchange

Products


Release

R2023a

Community Treasure Hunt

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

Start Hunting!