How to shift experimental data (not a function) in a loglog plot?

3 views (last 30 days)
I am trying to shift data just for viewing purposes, the actual values would not be relevant. I just don't want the data to overlap. Since it is on a logartithmic scale, it is not as direct as adding a factor to each value. And all recommendations I see involve shifting the mathematical log function. I wonder if there is a way to evenly shift experimental data on a loglog scale.
clear; clc; clf; close all;
x = [0.015 0.02 0.05 0.1 0.2 0.3 0.4 0.5];
y1 = [1.1302e-11 1.9874e-11 3.5178e-11 8.0091e-11 1.6816e-10 2.3635e-10 3.3775e-10 4.1115e-10];
y1fit = [1.2258e-11 1.6337e-11 4.0783e-11 8.1477e-11 1.6278e-10 2.4401e-10 3.252e-10 4.0636e-10];
y2 = [7.3093e-11 8.5947e-11 1.5178e-10 2.3051e-10 3.121e-10 4.0186e-10 4.8517e-10 5.8097e-10];
y2fit = [7.3686e-11 8.6974e-11 1.4748e-10 2.199e-10 3.2787e-10 4.1418e-10 4.8887e-10 5.5596e-10];
y3 = [2.2116e-11 3.3031e-11 8.0283e-11 1.3912e-10 2.7158e-10 4.16e-10 5.8192e-10 7.2361e-10];
y3fit = [2.3459e-11 3.0991e-11 7.5229e-11 1.4714e-10 2.8781e-10 4.2612e-10 5.6293e-10 6.9864e-10];
figure
a = loglog(x, y1,'ko', 'MarkerFaceColor', 'b', 'MarkerSize',10);
hold on
a1 = loglog(x, y1fit, 'k--', 'LineWidth', 2);
b = loglog(x, y2,'kd', 'MarkerFaceColor', 'm', 'MarkerSize',10);
b1 = loglog(x, y2fit, 'k--','LineWidth', 2);
c = loglog(x, y3,'ks', 'MarkerFaceColor', 'r', 'MarkerSize',10);
c1 = loglog(x, y3fit, 'k--', 'LineWidth', 2);
I edited it in paint; getting something like this would be the goal, no overlapping data and can easily view the different slopes (I don't mind the higher y value).

Accepted Answer

Les Beckham
Les Beckham on 5 Jan 2023
Edited: Les Beckham on 5 Jan 2023
Instead of adding an offset, multiply to shift the data. I used a factor of 10 as an example.
x = [0.015 0.02 0.05 0.1 0.2 0.3 0.4 0.5];
y1 = [1.1302e-11 1.9874e-11 3.5178e-11 8.0091e-11 1.6816e-10 2.3635e-10 3.3775e-10 4.1115e-10];
y1fit = [1.2258e-11 1.6337e-11 4.0783e-11 8.1477e-11 1.6278e-10 2.4401e-10 3.252e-10 4.0636e-10];
y2 = [7.3093e-11 8.5947e-11 1.5178e-10 2.3051e-10 3.121e-10 4.0186e-10 4.8517e-10 5.8097e-10];
y2fit = [7.3686e-11 8.6974e-11 1.4748e-10 2.199e-10 3.2787e-10 4.1418e-10 4.8887e-10 5.5596e-10];
y3 = [2.2116e-11 3.3031e-11 8.0283e-11 1.3912e-10 2.7158e-10 4.16e-10 5.8192e-10 7.2361e-10];
y3fit = [2.3459e-11 3.0991e-11 7.5229e-11 1.4714e-10 2.8781e-10 4.2612e-10 5.6293e-10 6.9864e-10];
figure
a = loglog(x, y1,'ko', 'MarkerFaceColor', 'b', 'MarkerSize',10);
hold on
a1 = loglog(x, y1fit, 'k--', 'LineWidth', 2);
b = loglog(x, 10*y2,'kd', 'MarkerFaceColor', 'm', 'MarkerSize',10); % <<< multiply to shift up
b1 = loglog(x, 10*y2fit, 'k--','LineWidth', 2); % <<< multiply to shift up
c = loglog(x, y3,'ks', 'MarkerFaceColor', 'r', 'MarkerSize',10);
c1 = loglog(x, y3fit, 'k--', 'LineWidth', 2);
grid on

More Answers (2)

William Rose
William Rose on 5 Jan 2023
@Alfredo Scigliani, Multiply all y-values of the trace in quesiton by a constant. This will cause a parallel vertical shift on a log-log plot.
  1 Comment
William Rose
William Rose on 5 Jan 2023
x=10.^(sort(2*rand(1,8))-2);
y1=x/10;
y2=x.^2;
subplot(211)
loglog(x,y1,'-ro',x,y2,'-bx');
xlim([.01,1]); title('Before shift');
legend ('y1','y2','location','southeast')
subplot(212)
loglog(x,10*y1,'-ro',x,y2,'-bx'); %parallel shift of y1
xlim([.01,1]); title('After shift');
legend ('shifted y1','y2','location','southeast')
Good luck

Sign in to comment.


Fifteen12
Fifteen12 on 5 Jan 2023
I believe you have to do it point by point. Since a 1 unit increase is equivalen to 10x the value, if you wanted to shift upwards by 1 unit you would have to times by 10. For example:
x = [0.015 0.02 0.05 0.1 0.2 0.3 0.4 0.5];
y = [1.2258e-11 1.6337e-11 4.0783e-11 8.1477e-11 1.6278e-10 2.4401e-10 3.252e-10 4.0636e-10];
yshifted = y * 10;
loglog(x, y, 'r', 'LineWidth', 2)
hold on
loglog(x, yshifted, 'b', 'LineWidth', 2)
You can change the shift value from 10 to any other digit as well.

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

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

Start Hunting!