Log-Log Plot

조회 수: 13 (최근 30일)
Raj Arora
Raj Arora 2023년 8월 30일
편집: Raj Arora 2023년 8월 30일
I have a log-log graph generated by a specific software. I aim to replicate this graph precisely using MATLAB. I've made an attempt and although I'm getting close, it's not an exact match. The attached (softwarePlot.png) displays the original graph for reference. I'm particularly concerned about emulating the software's x-axis definition and maintaining the uniform spacing between each point. Enclosed is the MATLAB code I've written so far.
The spacing between the values on the x-axis, particularly between 0.2 to 1 and 1 to 5, is too small. I would like these intervals to be larger in the matlab code.
Additionally, I'm interested in recreating the red line seen in the software's image, which represents the fitted line between the two blue lines.
MATLAB CODE
Q = importdata('data.txt');
figure;
semilogy(Q(:,1), Q(:,2),'og','MarkerSize',5,'MarkerFaceColor', 'g');
desiredXTicks = [0.2 1 5 10 20 40 60 75 90 95 98 99.5]; % Set the desired tick positions
xticks(desiredXTicks);
customXAxisLimits = [2/10,0.98*100]; % Adjust the values as needed
xlim(customXAxisLimits);
hold on
semilogy(Q(:,3),Q(:,4),'-b','linewidth', 1.5)
semilogy(Q(:,3),Q(:,5),'-b','linewidth', 1.5)
semilogy(Q(:,6),Q(:,7),'ok')
ylim([100,1000000]);
The spacing between the values on the x-axis, particularly between 0.2 to 1 and 1 to 5, is too small. I would like these intervals to be larger in the matlab code.

답변 (1개)

Walter Roberson
Walter Roberson 2023년 8월 30일
이동: Walter Roberson 2023년 8월 30일
Q = importdata('data.txt');
figure;
semilogy(Q(:,1), Q(:,2),'og','MarkerSize',5,'MarkerFaceColor', 'g');
desiredXTicks = [0.2 1 5 10 20 40 60 75 90 95 98 99.5]; % Set the desired tick positions
xticks(desiredXTicks);
customXAxisLimits = [2/10,0.98*100]; % Adjust the values as needed
xlim(customXAxisLimits);
hold on
semilogy(Q(:,3),Q(:,4),'-b','linewidth', 1.5)
semilogy(Q(:,3),Q(:,5),'-b','linewidth', 1.5)
semilogy(Q(:,6),Q(:,7),'ok')
ylim([100,1000000]);
ax = gca;
ax.XScale = 'log';
ax.XDir = 'reverse';
  댓글 수: 2
Walter Roberson
Walter Roberson 2023년 8월 30일
However, the scale on the X axis is simply inconsistent.
Consider the graph distance between 10 and 20.
If the axes were linear, then when you went the same graph distance to the left of 20 you should get to pretty close to 30. But you do not -- you get to somewhere close to 40.
If the axes were log, then going the same graph distance to the left of 20 you should get the same ratio, 20:10 = 2, so you should get close to 40. Which isn't quite right on, but is close enough to continue testing the hypothesis that the axes scale is log. So now go the same distance to the left of the 40. If the log hypothesis is true, then you should have the same ratio, getting you to about 80. But you do not -- you get to about 60.
Therefore sometimes the axes scale is log-ish and sometimes the axes scale is linear-ish... but goes back to log-ish later.
You could probably reverse-engineer selective stretching of scales to match, but it would be ad-hoc rather than meaningful.
Raj Arora
Raj Arora 2023년 8월 30일
편집: Raj Arora 2023년 8월 30일
Thanks Walter for your prompt reply. Can you suggest how can we get a trend line between 2 blue lines.
Actually earlier I was doing this
%set(gca, 'XDir', 'reverse');
%set(gca, 'YScale', 'log');

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

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by