large errorbars on semilogx

3 visualizzazioni (ultimi 30 giorni)
Sonali
Sonali il 18 Mar 2024
Commentato: Steven Lord il 19 Mar 2024
I am trying to plot mid vs columns. And I am getting either partial or very elongated errorbars. Please find the datafile and plot below. Will really appreciate a solutions to this issue. Thanks.

Risposte (2)

Steven Lord
Steven Lord il 18 Mar 2024
What's the difference between the logarithm of 1 and the logarithm of 2?
format longg
x1 = log([1 2])
x1 = 1×2
0 0.693147180559945
delta1 = diff(x1)
delta1 =
0.693147180559945
Now what's the difference between the logarithms of 11 and 12?
x2 = log([11 12])
x2 = 1×2
2.39789527279837 2.484906649788
delta2 = diff(x2)
delta2 =
0.0870113769896297
How much larger is the difference between logarithms?
delta1/delta2
ans =
7.96616723629781
So an errorbar of length 1 will be drawn much longer (about 8 times as long) if it starts around x = 1 than if it starts around x = 11. What value would you have to use as the right endpoint for the x = 11 errorbar to make it appear as long as the errorbar of length 1 starting at x = 1?
x3right = exp(x2(1)+delta1)
x3right =
22
semilogx([1 2 NaN 11 12 NaN 11 x3right], [1 1 1 2 2 2 3 3])
ylim([0 4])
The line at y = 1 looks to be about the same length as the one at y = 3.
A quick check on my monitor with a ruler shows that the line at y = 2 is about an eighth as long as the lines at y = 1 and y = 3.
  2 Commenti
Sonali
Sonali il 19 Mar 2024
any solution to that?
Steven Lord
Steven Lord il 19 Mar 2024
Solution to what? To making the error bars longer?
Either don't use a log scale on the axes or change your data about how long the error bars should be. In my example, the approach involving x3right was an example of the latter. For an example of the former:
plot([1 2 NaN 11 12], [1 1 1 2 2])
ylim([0 3])
These lines are the same length on my screen.

Accedi per commentare.


Voss
Voss il 18 Mar 2024
What you see is because of the log XScale:
  • Partial errorbars: If the left endpoint of the errorbar would be <= 0, it is not rendered on log scale, because log of a number <= 0 is complex or -Inf.
  • Elongated errorbars: also an effect of logarithmic x-scaling. For example, a unit-length segment takes up more space in the plot if it goes from 1 to 2 than it takes if it goes from 10 to 11 (that's just how logarithmic scales work).
semilogx([1 2],[1 1])
hold on
semilogx([10 11],[1 1])
xlim([0.1 100])
  5 Commenti
Voss
Voss il 19 Mar 2024
Modificato: Voss il 19 Mar 2024
Please share your code, at least the line of code where you call the errorbar function.
Or compare your errorbar call to mine and figure out what you need to change to make it work.
Sonali
Sonali il 19 Mar 2024
figure()
set(gca(),'XScale','log')
semilogx((col1),mid,'*m',LineStyle='none',LineWidth=1.5,MarkerSize= 5 )
hold on
errorbar(col1,mid,(err_col1),'horizontal',LineStyle='none', Color='m',LineWidth = 0.1,CapSize=2)
grid on
hold off

Accedi per commentare.

Categorie

Scopri di più su Errorbars in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by