필터 지우기
필터 지우기

How do I plot logarithmic error?

조회 수: 18 (최근 30일)
Niek Blikslager
Niek Blikslager 2020년 8월 17일
댓글: J. Alex Lee 2020년 8월 19일
I have data that I want to plot on a log y-scale because it's not linear. When I plot the error, the bars are not of equal length (lower error looks larger) because of the log y-scale. How do I transform the error so it becomes the relative error and I get error bars of equal lengths above and below the datapoints?
I want to plot the error as a shaded area around the main data, so I need not plot a line above and below the main data. How do I calculate these two lines?
I don't calculate the logarithm of my data, I just plot it, and then change the y-axis through:
set(gca,'YScale','log');
Edit:
For clarity a figure of the problem. The dotted lines is the 'data + error', and the 'data - error'. Because of the log scale, the error seems way lager for the 'data - error', eventhough the error margin is equal above and below the data line. How do I transform the error so it has an equal distance between the error above and below the data line? I Hope this is more clear now.
data = [1.0 1.4 1.5 2.6 1.9 1.9 3.6 4.3 9.5 9.2];
error = [1.2 1.1 1.4 2.0 1.5 1.2 2.2 2.6 0.6 0.7];
dataPlus = data + error;
dataMin = data - error;

채택된 답변

J. Alex Lee
J. Alex Lee 2020년 8월 18일
In log space, spacing is multiplicative, not additive, so you want to express your top and bottom curves as multiples of your base curve
clc;
close all;
clear;
data = [1.0 1.4 1.5 2.6 1.9 1.9 3.6 4.3 9.5 9.2];
err = [1.2 1.1 1.4 2.0 1.5 1.2 2.2 2.6 0.6 0.7];
% above
dataPlus = data + err;
dataPlusMult = dataPlus./data;
% below
dataMinus = data ./ dataPlusMult;
figure(1); cla; hold on;
plot(data,'-')
plot(dataPlus,'--')
plot(dataMinus,'--')
set(gca,'YScale','log')
  댓글 수: 2
Niek Blikslager
Niek Blikslager 2020년 8월 19일
This is exactly what I wanted, thanks a lot for the help!
J. Alex Lee
J. Alex Lee 2020년 8월 19일
Glad it helps.
Just to comment that your plot no longer reflects what you actually wanted to convey, if what you wanted to convey is data +/- err.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

J. Alex Lee
J. Alex Lee 2020년 8월 17일
use the log10() function? The question isn't super clear...
  댓글 수: 2
Niek Blikslager
Niek Blikslager 2020년 8월 18일
I added some information, I hope the question is more clear now.
J. Alex Lee
J. Alex Lee 2020년 8월 18일
the plot of the data is what it is, you can't change how it looks without changing the error values themselves...

댓글을 달려면 로그인하십시오.

카테고리

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