How to label each line in the plot

조회 수: 17 (최근 30일)
Med Future
Med Future 2022년 3월 28일
답변: Scott MacKenzie 2022년 3월 28일
Hello everyone i hope you are doing well. I want to label y axis with the value i get from
Value= unique(whiteLineRows1);
but when i plot it gives the Value= as in the image attached
How can i plot the value on each line
path = 'C:\Users\DELL\Documents\MATLAB\Examples\R2021b\phased\ModClassificationOfRadarAndCommSignalsExample\NewDataset\DatasetGeneration\Detection\ImageDetection\imageclass_001001.png';
rgbImage = imread(path);
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels > 1
grayImage = rgbImage(:, :, 3);
else
grayImage = rgbImage;
end
[rows, columns, numberOfColorChannels] = size(rgbImage);
mask = grayImage >= 128;
[labeledImage, numRegions] = bwlabel(mask);
props = regionprops(labeledImage, 'Area', 'Centroid');
allLengths = [props.Area];
centroids = vertcat(props.Centroid);
whiteLineRows1 = centroids(:, 2);
Value= unique(whiteLineRows1);
hold on
Levels=length(Value);
for k = 1 : Levels
str = sprintf('Value %d', Value(k))
yline(Value, 'LineWidth', 2, 'Color', 'r','Label',str);
hold off
end

채택된 답변

Scott MacKenzie
Scott MacKenzie 2022년 3월 28일
The main problem in the image is that the values are superimposed. This can be fixed by using an index into the Values array for each line:
for k = 1 : Levels
str = sprintf('Value %d', Value(k))
yline(Value(k), 'LineWidth', 2, 'Color', 'r','Label',str); % add index into Value
hold off
end

추가 답변 (0개)

카테고리

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

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by