How to mark the shadded area in the scatter plot

조회 수: 9 (최근 30일)
Tayyaba Bano
Tayyaba Bano 2023년 5월 12일
답변: Tayyaba Bano 2023년 6월 15일
Hi,
I want to show a scatter plot with some shadded region in a lighter shade. I tried with 'fill' and 'patch' command but unfortunately its not working.
I want two shaded regions, 1. between maximum and average, and 2. between minimum and average.
I attach the code and the figure.
Thanks
t = Max100(:,1);
z = Max100(:,2);
plot(t,z,'d','Markersize',8,'MarkerFaceColor',[0 0.4470 0.7410],'MarkerEdgeColor',[0 0.4470 0.7410])
hold on
g = av100(:,1);
h = av100(:,2);
plot(g,h,'d','Markersize',8,'MarkerFaceColor',[0.9290 0.6940 0.1250],'MarkerEdgeColor',[0.9290 0.6940 0.1250])
hold on
c = min100(:,1);
d = min100(:,2);
plot(c,d,'d','Markersize',8,'MarkerFaceColor',[0.8500 0.3250 0.0980],'MarkerEdgeColor',[0.8500 0.3250 0.0980])
legend ('Maximum','Average', 'Minimum','FontSize',14, FontName='Arial')

답변 (2개)

Sandeep Mishra
Sandeep Mishra 2023년 6월 14일
Hello Tayyaba,
I understood that you are plotting three plots "Maximum", "Average" and "Minimum" and want to shade the regions between Maximum - Average and Average - Minimum plots.
In MATLAB, the "fill" function provides you the functionality to plot filled polygonal regions as patches with vertices at the (x,y) locations specified by X and Y.
You can implement the fill function like the below example.
% Maximum plot
t = [1 2 3 4 5 6 7 8];
z = nthroot(t, 2.8);
maxPlot = plot(t,z,'d','Markersize',8,'MarkerFaceColor',[0 0.4470 0.7410],'MarkerEdgeColor',[0 0.4470 0.7410]);
% Average plot
hold on
g = [1 2 3 4 5 6 7 8];
h = nthroot(g, 3);
avgPlot = plot(g,h,'d','Markersize',8,'MarkerFaceColor',[0.9290 0.6940 0.1250],'MarkerEdgeColor',[0.9290 0.6940 0.1250]);
% Filling the region between Maximum and Average plot with blue color
fill([g fliplr(t)], [z fliplr(h)], 'b');
% Minimum plot
c = [1 2 3 4 5 6 7 8];
d = nthroot(c, 3.2);
minPlot = plot(c,d,'d','Markersize',8,'MarkerFaceColor',[0.8500 0.3250 0.0980],'MarkerEdgeColor',[0.8500 0.3250 0.0980]);
% Filling the region between Average and Minimum plot with green color
fill([g fliplr(c)], [h fliplr(d)], 'g')
% Adding plots, labels, and text parameters to legend
legend ([maxPlot, avgPlot, minPlot],'Maximum','Average', 'Minimum','FontSize',14, FontName='Arial')
hold off
You can refer to the below documentation to learn more about "fill" in MATLAB

Tayyaba Bano
Tayyaba Bano 2023년 6월 15일
Thank you very much for your kind reply.
Regards
Tayyaba

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by