Clabel style in-line text for plot
8 views (last 30 days)
Show older comments
I use 'clabel(C,h,v)' to add in-line text to the lines of the contour plot. Is there a way to do this for normal line plots? The example below shows what I mean, the orange line has 200 in-line, but the 900, 1200, 1400 & 1700 don't. Is there a way to do this for a normal line plot?
0 Comments
Answers (1)
Narvik
on 30 Oct 2024 at 9:46
Hi Joris,
As per my understanding, you are trying to add in-line labels to line plots.
You can use the "text" function to add in-line labels to line plots.
Refer to the following documentation for more information on the "text" function:
Refer to the following sample code with a simple contour and line plot with inline labels:
% Contour plot data
[X, Y] = meshgrid(-3:0.1:3, -3:0.1:3);
Z = X.^2 + Y.^2;
% Create the contour plot
figure;
[C, h] = contour(X, Y, Z, 8, 'LineWidth', 1);
clabel(C, h, 'FontSize', 8, 'Color', 'k');
hold on;
% Line plot data
x = -3:0.1:3;
y = x;
% Plot the line
plot(x, y, '-r', 'LineWidth', 1.5);
% Using "text" to add in-line label on the line plot
labelIndex = find(x == 0);
text(x(labelIndex), y(labelIndex), ' y = x ', 'BackgroundColor', 'w', 'VerticalAlignment', 'middle', 'HorizontalAlignment', 'center', 'Color', 'r');
% Customize plot
xlabel('X-axis');
ylabel('Y-axis');
title('Contour and Line Plot with In-line Labels');
grid on;
hold off;
Hope this helps!
0 Comments
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!