I'm using Octave 9.2.0
Could somebody please explain why an interpolated value (in which I get the X and Y coordinates) will now show correctly when presenting the data in logarithmic scale?
Its only the presented data thats in logarithmic scale.
Example:
The X and Y are in linear scale and the found places where the green line crosses the blue lines are working great. Even if you zoom in you can see that they are correct. But its hard do visualize. Hence, I want the Y axis to be in logarithmic scale.
But then the found points will not be correct anymore.
It becomes even more obvious if I zoom in on the semilogy plot.
If I zoom in on the normal linear plot function you can see that its spot on.
I fail to understand how this problem can occur since its only the presentation of the data thats different. Is this a bug in Octave or am I missing something?
UPDATE!
Values
x_border=[89.851, 89.381, 88.206, 84.483, 76.524, 63.118, 48.013, 32.873, 20.891];
y1_limit = [950.64, 988.06, 238.63, 333.22, 902.78, 282.25, 776.69, 993.59, 891.05];
y2_limit = [2091.4, 2173.7, 524.99, 733.09, 1986.1, 620.95, 1708.7, 2185.9, 1960.3];
y3_limit = [5.2596e+06, 5.0604e+06, 2.0953e+07, 1.5005e+07, 5.5385e+06, 1.7715e+07, 6.4376e+06, 5.0323e+06, 5.6113e+06];
measured_y=[435.18, 1610.4, 7327.3, 39667, 2.2852e+05, 1.2228e+06, 5.4267e+06, 1.6834e+07, 3.5808e+07];
limit1_pts(1), limit1_pts(2) = [89.638, 967.59];
limit2_pts(1), limit2_pts(2) = [89.291, 2047.6];
limit3_pts(1), limit3_pts(2) =[46.819, 6.3267e+06];
plot for logaritmic scale
figure(999);
clf;
semilogy(x_border, y1_limit,'-.','linewidth',1,'color','b');
hold on;
semilogy(x_border, y2_limit,'-','linewidth',1,'color','b');
hold on;
semilogy(x_border, y3_limit,'-.','linewidth',1,'color','b');
hold on;
semilogy(x_border,measured_y,'-','linewidth',1,'color','g');
hold on;
semilogy(limit1_pts(1), limit1_pts(2),'*','linewidth',3,'color','r');
hold on;
semilogy(limit2_pts(1), limit2_pts(2),'x','linewidth',3,'color','r');
hold on;
semilogy(limit3_pts(1), limit3_pts(2),'*','linewidth',3,'color','r');
hold on;
The same plot for linear is:
figure(999);
clf;
plot(x_border, y1_limit,'-.','linewidth',1,'color','b');
hold on;
plot(x_border, y2_limit,'-','linewidth',1,'color','b');
hold on;
plot(x_border, y3_limit,'-.','linewidth',1,'color','b');
hold on;
plot(x_border,measured_y,'-','linewidth',1,'color','g');
hold on;
plot(limit1_pts(1), limit1_pts(2),'*','linewidth',3,'color','r');
hold on;
plot(limit2_pts(1), limit2_pts(2),'x','linewidth',3,'color','r');
hold on;
plot(limit3_pts(1), limit3_pts(2),'*','linewidth',3,'color','r');
hold on;
As I explained in the comments, and also was by Chris Luengo in his post,
the fact that in a semi-log plot the lines don't appear to intersect in the right point is
an artifact of semilogy
: the log plot draws linear segments between the points,
but in your application the linear segments are correct only with the linear axis.
With the log axis the same segments should be represented as curves, but semilogy
doesn't know how to do that. Also, as we'll see, those curves don't look very nice,
Here's an approach that will show the log plot as it should, if the segments connecting
the points are an essential part of the application, as they seem to be in your case:
For the four lines, (x_border
, y1_limit
), (x_border
, y2_limit
), (x_border
, y3_limit
)
and (x_border
, measured_y
) I'll intercalate NPlus = 100
new points between each two
successive points, using linear interpolation between those two points (there will
be about 800 points on each line now). Then just plot
/semilogy
the finer data instead of
the original data: we'll see the lines transforming to curves and the intersections will
now match:
x_border = [89.851, 89.381, 88.206, 84.483, 76.524, 63.118, 48.013, 32.873, 20.891];
y1_limit = [950.64, 988.06, 238.63, 333.22, 902.78, 282.25, 776.69, 993.59, 891.05];
y2_limit = [2091.4, 2173.7, 524.99, 733.09, 1986.1, 620.95, 1708.7, 2185.9, 1960.3];
y3_limit = [5.2596e+06, 5.0604e+06, 2.0953e+07, 1.5005e+07, 5.5385e+06, 1.7715e+07, 6.4376e+06, 5.0323e+06, 5.6113e+06];
measured_y=[435.18, 1610.4, 7327.3, 39667, 2.2852e+05, 1.2228e+06, 5.4267e+06, 1.6834e+07, 3.5808e+07];
NPlus = 100;
xi = [x_border(1)];
y1i = [y1_limit(1)];
y2i = [y2_limit(1)];
y3i = [y3_limit(1)];
myi = [measured_y(1)];
for i = 1:length(x_border)-1
nx = length(xi);
xi(nx) = []; y1i(nx) = []; y2i(nx) = []; y3i(nx) = []; myi(nx) = [];
xi = cat(2, xi, linspace(x_border(i), x_border(i+1), NPlus+2));
y1i = cat(2, y1i, linspace(y1_limit(i), y1_limit(i+1), NPlus+2));
y2i = cat(2, y2i, linspace(y2_limit(i), y2_limit(i+1), NPlus+2));
y3i = cat(2, y3i, linspace(y3_limit(i), y3_limit(i+1), NPlus+2));
myi = cat(2, myi, linspace(measured_y(i), measured_y(i+1), NPlus+2));
endfor
limit1_pts = [89.638, 967.59];
limit2_pts = [89.291, 2047.6];
limit3_pts =[46.819, 6.3267e+06];
figure(999);
clf;
semilogy(xi, y1i,'-.','linewidth',1,'color','b');
hold on;
semilogy(xi, y2i,'-','linewidth',1,'color','b');
hold on;
semilogy(xi, y3i,'-.','linewidth',1,'color','b');
hold on;
semilogy(xi, myi,'-','linewidth',1,'color','g');
hold on;
semilogy(limit1_pts(1), limit1_pts(2),'*','linewidth',3,'color','r');
hold on;
semilogy(limit2_pts(1), limit2_pts(2),'x','linewidth',3,'color','r');
hold on;
semilogy(limit3_pts(1), limit3_pts(2),'*','linewidth',3,'color','r');
hold on;
The result is pretty ugly, but those funny looking arcs are the correct representation with the log y axis of the lines connecting the points with the linear axis. Actually I haven't done any calculation, I just added evenly distributed points on the segments for the purpose of showing how the original points are connected. If we do the same with the linear axis, there is no change to the plot, the result is exactly the same as before adding the points:
figure(999);
clf;
plot(xi, y1i,'-.','linewidth',1,'color','b');
hold on;
plot(xi, y2i,'-','linewidth',1,'color','b');
hold on;
plot(xi, y3i,'-.','linewidth',1,'color','b');
hold on;
plot(xi, myi,'-','linewidth',1,'color','g');
hold on;
plot(limit1_pts(1), limit1_pts(2),'*','linewidth',3,'color','r');
hold on;
plot(limit2_pts(1), limit2_pts(2),'x','linewidth',3,'color','r');
hold on;
plot(limit3_pts(1), limit3_pts(2),'*','linewidth',3,'color','r');
hold on;