Plotting negative errorbar on semilogx
11 ビュー (過去 30 日間)
古いコメントを表示
Hi I have got some half errorbars plotted on the semilogx. I understand that its possibly because of negative/complex values. I have tried most of the suggestions made to the previous posts. But they seem to not work with my program. Will really appreciate some help here.
Please find the file of data attached.
I am trying to errorbars for plot mid(Y) v/s density(X) on a semilogx using command below:
semilogx(density,mid,'*m',LineStyle='none',MarkerSize=4)
hold on
errorbar(density,mid,err,'horizontal',LineStyle='none', Color='red',LineWidth = 0.1,CapSize=2)
5 件のコメント
the cyclist
2024 年 1 月 24 日
Let's take a look at what your data + error bars look like, plotted in linear space:
data = readtable("file.xlsx");
density = data.density;
mid = data.mid;
err = data.err;
figure
plot(density,mid,'*m',LineStyle='none',MarkerSize=4)
hold on
errorbar(density,mid,err,'horizontal',LineStyle='none', Color='red',LineWidth = 0.1,CapSize=2)
and then just the data (without error bars) in log space:
data = readtable("file.xlsx");
density = data.density;
mid = data.mid;
err = data.err;
figure
semilogx(density,mid,'*m',LineStyle='none',MarkerSize=4)
As you realize, the error bars extend into the negative numbers, so their log will be complex.
But what do you want to show on the plot? More importantly, are those really the correct errorbars? I expect that the density cannot actually go negative, so that is the real problem.
回答 (2 件)
Sulaymon Eshkabilov
2024 年 1 月 24 日
This is how the nagtive values can be displayed in the plot:
D = readtable('file.xlsx');
IDX1 = log10(D.density)>0;
semilogx(D.density(IDX1),D.mid(IDX1),'*m',LineStyle='none',MarkerSize=4)
hold on
errorbar(D.density(IDX1),D.mid(IDX1),D.err(IDX1),'horizontal',...
LineStyle='none', Color='red',LineWidth = 0.1,CapSize=2)
IDX2 = log10(D.density)<=0;
Offset = 1e-13;
Density_Neg=D.density(IDX2)+Offset;
Mid_Neg = D.mid(IDX2);
Err_Neg = D.err(IDX2);
semilogx(Density_Neg,Mid_Neg,'bo',LineStyle='none',MarkerSize=6)
errorbar(Density_Neg,Mid_Neg,Err_Neg,'horizontal',LineStyle='none', Color='b',LineWidth = 0.2,CapSize=3)
hold off
legend('Mid: Density_{Pos}','Err: Density_{Pos}', 'Err: Density_{Neg}', ...
'Mid: Desnity_{Pos}', 'Location', 'Best')
Even though it says ignored but they are displayed as shown and can be tested.
N_total = numel(D.density) % ALL
N_pos = sum(IDX1) % Positive
N_neg = sum(IDX2) % Negative
The warning pops up because of the MATLAB's graphics set up:
In matlab.graphics.shape.internal.AxesLayoutManager>calculateLooseInset
In matlab.graphics.shape.internal/AxesLayoutManager/updateStartingLayoutPosition
In matlab.graphics.shape.internal/AxesLayoutManager/doUpdate
1 件のコメント
the cyclist
2024 年 1 月 24 日
I don't think this solution is handling the case where density is positive, but (density - err) is negative. Those are the points that have only "half" the errorbar (in the positive direction), and are at the heart of the question.
Sulaymon Eshkabilov
2024 年 1 月 24 日
編集済み: Sulaymon Eshkabilov
2024 年 1 月 25 日
It looks like this is how to display the missing half of error bar values. The solution with the x- axis limit set up:
D = readtable('file.xlsx');
IDX1 = log10(D.density)>0;
semilogx(D.density(IDX1),D.mid(IDX1),'*m',LineStyle='none',MarkerSize=4, Marker="square")
hold on
errorbar(D.density(IDX1),D.mid(IDX1),log10(D.err(IDX1)),'horizontal',...
LineStyle='none', LineWidth = 0.1,CapSize=2)
xlim([20 150])
4 件のコメント
the cyclist
2024 年 2 月 1 日
You never answered the question I asked in my earlier comment.
Your error bars extend to negative numbers. But surely you can't actually have negative density. How do you want to handle that?
You cannot make a sensible plot from non-sensible data.
dpb
2024 年 2 月 1 日
"surely you can't actually have negative density. How do you want to handle that?"
On log scale, one would generally use proportional error bands, not absolute, then the negative values wouldn't show up.
参考
カテゴリ
Help Center および File Exchange で Errorbars についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!