loglog plot command not working,gives linear plot
106 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
function f_plot(sr)
load(sr);
% nf=0;
lstr={'PTT predictions-0.1/s','Expt. Data-0.1/s','PTT predictions-0.3/s','Expt. Data-0.3/s','PTT predictions-1/s','Expt. Data-1/s','PTT predictions-3/s','Expt. Data-3/s','PTT predictions-10/s','Expt. Data-10/s'};
colorstring = 'kbgry';
figure(1); cla;
for i=1:1:no_of_eps_dot
% nf=nf+1;
% figure(nf);
hold on; grid on;
[mm ii]=find(ext_visc{i}<1e10);
plot(allt{i}(mm),ext_visc{i}(mm),'color',colorstring(i),'linewidth',1.5);
hold on
plot(t_expt{i},visc_expt{i},'*','color',colorstring(i));
xlabel('Time (sec)');
ylabel('Extensional Viscosity (Pa-sec)');
set(gca,'xLim',[0 20]);
set(gca,'yLim',[-0.5 1*10^5]);
name=sprintf('PTT Extensional Rheology :Plot of Extensional Viscosity vs time for Extensional rate for 2.PENC.');
title(name);
legend(lstr);
end
end
%
[SL: edited to apply code formatting]
0 Commenti
Risposte (2)
Steven Lord
il 22 Gen 2018
When I search this page for "loglog" (before writing this comment) I only found four hits and none of them were in your code. If one of the plot calls was supposed to be a loglog call, this is the expected behavior.
The first thing you do inside your loop is turn hold on. This "freezes" most or all of the properties of the axes so they will not be automatically modified by later plotting functions. One of the families of properties that hold on freezes is the scale: linear or log. Since no axes existed when that command was run, MATLAB populates the figure with a linear scale axes and freezes its properties. If you later call loglog to try to create a plot in that axes, it isn't allowed to change the XScale and YScale properties of the axes.
This is documented in the documentation for the loglog function: "If you attempt to add a loglog, semilogx, or semilogy plot to a linear axis mode graph with hold on, the axis mode remains as it is and the new data plots as linear."
To do what you want, add multiple plots to an axes in log scale, you will need to change the scale properties of the axes. You can do that before calling hold:
figure
% X scale will be logarithmic, y scale will be linear
axes('XScale', 'log', 'YScale', 'linear')
hold on
plot(1:10, 1:10)
or after:
figure
hold on
% x scale will be linear, y scale will be logarithmic
set(gca, 'YScale', 'log')
plot(1:10, 1:10)
0 Commenti
Jan
il 22 Gen 2018
At first a simplified version of your code:
function f_plot(sr)
load(sr); % BAD idea, now it is not clear, which variable have been imported
% Prefer: data = load(sr)
lstr = {'PTT predictions-0.1/s','Expt. Data-0.1/s','PTT predictions-0.3/s', ...
'Expt. Data-0.3/s','PTT predictions-1/s','Expt. Data-1/s', ...
'PTT predictions-3/s','Expt. Data-3/s','PTT predictions-10/s', ...
'Expt. Data-10/s'};
colorstring = 'kbgry';
figure(1);
AxesH = axes('NextPlot', 'add'); % Equivalent to: hold('on')
for i = 1:no_of_eps_dot
[mm, ii] = find(ext_visc{i}<1e10);
plot(allt{i}(mm), ext_visc{i}(mm), 'color', colorstring(i), 'linewidth', 1.5);
plot(t_expt{i}, visc_expt{i}, '*', 'color', colorstring(i));
end
grid on;
xlabel('Time (sec)');
ylabel('Extensional Viscosity (Pa-sec)');
set(AxesH, 'XLim', [0 20], 'YLim',[-0.5, 1e5]);
% Without SPRINTF:
name = ['PTT Extensional Rheology :Plot of Extensional Viscosity vs ', ...
'time for Extensional rate for 2.PENC.'];
title(name);
legend(lstr);
end
Now you do not set the parameters of the axes in each iteration, but once only.
You are asking for a loglog plot, but did not specify any log scaling anywhere. The X limits are [0, 20], and 0 is not a valid limit for a log scale.
So what is your actual question? Do you want to append:
set(AxesH, 'YScale', 'log')
?
2 Commenti
Vedere anche
Categorie
Scopri di più su Preprocessing Data in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!