Clabel style in-line text for plot

3 Ansichten (letzte 30 Tage)
Joris
Joris am 23 Sep. 2021
Beantwortet: Narvik am 30 Okt. 2024
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?

Antworten (1)

Narvik
Narvik am 30 Okt. 2024
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!

Kategorien

Mehr zu Line Plots finden Sie in Help Center und File Exchange

Produkte


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by