Highlight the region of plot or find some reliable and proper evaluation for the plot
86 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Soumyajit Samal
am 24 Jul. 2021
Beantwortet: Afiq Azaibi
am 17 Mär. 2023
Hello!
I was plotting a curve from a experimental data and the plot showed up like this. Now i want to highlight the region where the graph is plotted. Maybe kind of joining the peaks together and lows together or maybe through a trendline or simply joining the peaks and lows together.
Please guide me to do that. Or if any suggestions on how to plot something reliable and easy to infer from this plot, is highly appeciated.
Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Afiq Azaibi
am 17 Mär. 2023
If you'd like to highlight a region of the line chart, starting in R2023a you can use the xregion and yregion functions:
ydata = rand(1,100);
plot(ydata);
% Find the indices of the largest and smallest value in ydata.
minIndex = find(ydata==min(ydata));
maxIndex = find(ydata==max(ydata));
% Highlight the region between the highest and lowest value.
xregion(maxIndex, minIndex, 'FaceColor', 'g');
0 Kommentare
Weitere Antworten (1)
Image Analyst
am 24 Jul. 2021
Try this, and adapt as needed:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);
theta = 0 : 32*pi;
period = 30;
y = cos(2 * pi * theta / period);
plot(theta, y, 'b-', 'LineWidth', 2)
grid on;
% Shade the plot between 20 and 60 with red
ShadePlot(20, 60, 'r')
% --------------------------------------------------------------------
% Shades the plot with the specified color.
% Sample call:
% % Have a red zone from 0-159.
% colors = 'r';
% ShadePlot(0, 159, colors);
function ShadePlot(x1, x2, theColor)
try
hold on;
xl = xlim();
yl = ylim();
y = [yl(1), yl(1), yl(2), yl(2), yl(1)];
if theColor ~= 0
% If the zone is not supposed to be transparent/unshaded/untinted.
x = [x1, x2, x2, x1, x1];
fillHandle = fill(x, y, theColor, 'FaceAlpha', 0.1);
% Put up text labels
if x1 > 0 && x1 < 255
text(x1 + 1, 0.95*yl(2), num2str(x1), 'Color', [0, 0.5, 0]);
end
if x2 > 0 && x2 < 255
text(x2 + 1, 0.95*yl(2), num2str(x2), 'Color', [0, 0.5, 0]);
end
end
% Force immediate update of display.
drawnow;
catch ME
% Alert the user of the error.
errorMessage = sprintf('Error in program %s.\nError Message:\n%s', ...
mfilename, ME.message);
% Print the error message out to a static text on the GUI.
fprintf('%s\n', errorMessage);
uiwait(errordlg(errorMessage)); % Pop up message.
end
return; % from ShadePlot()
end
3 Kommentare
Image Analyst
am 24 Jul. 2021
Bearbeitet: Image Analyst
am 24 Jul. 2021
You say "that part of the graph only" but don't say what "that part" is.
When you say "highlight the region where the graph is plotted", well to me, that means the entire graph. What does it mean to you? Can you attach a picture that shows where you want the shading to be?
Have you seen the FAQ:
Siehe auch
Kategorien
Mehr zu Graphics Performance finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!