Borrar filtros
Borrar filtros

log-log plot

4 visualizaciones (últimos 30 días)
Raj Arora
Raj Arora el 29 de Ag. de 2023
Editada: Raj Arora el 29 de Ag. de 2023
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. 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')
hold on
a = Q(:, 3);
a = a(~isnan(a));
b = Q(:, 4);
b = b(~isnan(b));
p = polyfit(Q(:,1),Q(:,2),2)
trend_y = polyval(p, Q(:,1));
plot(Q(:,1), trend_y, '-r','linewidth', 1.5)
legend({'Discharge data','5% lower limit','95% upper limit','Outliers'},'Location','Northwest','fontsize',14)
legend boxoff
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.

Respuestas (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 29 de Ag. de 2023
If understood your posted question, this is how to solve this issue using reverse X-axis data:
Q = importdata('DATA_IN.txt'); % Your data file name is renamed
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')
hold on
a = Q(:, 3);
a = a(~isnan(a));
b = Q(:, 4);
b = b(~isnan(b));
p = polyfit(Q(:,1),Q(:,2),2);
trend_y = polyval(p, Q(:,1));
plot(Q(:,1), trend_y, '-r','linewidth', 1.5)
legend({'Discharge data','5% lower limit','95% upper limit','Outliers'},'Location','Northwest','fontsize',14)
legend boxoff
ylim([100,1000000]);
set(gca, 'XDir','reverse');
grid on
  1 comentario
Raj Arora
Raj Arora el 29 de Ag. de 2023
Editada: Raj Arora el 29 de Ag. de 2023
The plot you attached here is identical to what can be produced from the code I've provided. I've included a .png image for your reference, displaying varying distances for labels on the x-axis (0.2, 1, 5, 10, 20, 40, 60, 75, 90, 95, 95) – this is my intended outcome. Furthermore, the fitted curve corresponds to a line fitted between two blue reference lines, rather than being represented as a scatter plot. (The red color line (in the figure you attached) is the fitted curve for scatter plot not the fitten line exactly between 2 blue lines)

Iniciar sesión para comentar.

Categorías

Más información sobre Graph and Network Algorithms en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by