Clabel style in-line text for plot

조회 수: 3 (최근 30일)
Joris
Joris 2021년 9월 23일
답변: Narvik 2024년 10월 30일
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?

답변 (1개)

Narvik
Narvik 2024년 10월 30일
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!

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by