필터 지우기
필터 지우기

What is the best way to fill the areas between lines in a graph with logarithmic axis?

조회 수: 6 (최근 30일)
Hello!
Would someone be so kind as to help me in my attempt to fill the area between two curves?
The x-axis must be logarithmic! Unfortunately, I don't know where my mistake lies and would be grateful for help.
Workable code is below.
Thanks and greetings
faktorOG = [1.45 1.2 1.2 1.2 1.2 1.2 1.2 1.2];
faktorUG = [0.65 0.8 0.8 0.8 0.8 0.65 0.6 0.5];
Frequenzen = [125 250 500 1000 2000 4000 5000 8000];
x = Frequenzen;
% Figure Toleranzbereich Ober- und Unter Grenze
figure
grid on
hold on
semilogx(x,faktorOG, 'k-',...
x,faktorUG, 'k:','LineWidth',1.5)
inBetweenRegionX = [1:length(faktorUG), length(faktorOG):-1:1];
inBetweenRegionY = [faktorUG, fliplr(faktorOG)];
% Display the area first so it will be in the background.
fill(inBetweenRegionX, inBetweenRegionY, 'g');
xticks([125 250 500 1000 2000 4000 10000])
xticklabels({'125','250','500','1000','2000','4000','10000'})
legend('Obergrenze','Untergrenze')

답변 (1개)

Sandeep Mishra
Sandeep Mishra 2023년 6월 14일
Hello Stefan,
I understood that you are trying to plot two graphs "faktorOG" and "faktorUG" on the semilog axis "Frequenzen" and want to fill the area between these two 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 below.
% Coloring the area between two plots using "flip"
fill([x fliplr(x)], [faktorOG fliplr(faktorUG)], 'r');
You can refer to the below documentation to learn more about "fill" in MATLAB

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by