Show Sidebar Hide Sidebar

# Log Plots in MATLAB

How to make a plot with logarithmic axes in MATLAB.

#### Logarithmic Axes

``````% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

trace1 = struct(...
'x', [0, 1, 2, 3, 4, 5, 6, 7, 8], ...
'y', [8, 7, 6, 5, 4, 3, 2, 1, 0], ...
'type', 'scatter');
trace2 = struct(...
'x', [0, 1, 2, 3, 4, 5, 6, 7, 8], ...
'y', [0, 1, 2, 3, 4, 5, 6, 7, 8], ...
'type', 'scatter');
data = {trace1, trace2};
layout = struct(...
'xaxis', struct(...
'type', 'log', ...
'autorange', true), ...
'yaxis', struct(...
'type', 'log', ...
'autorange', true));
response = plotly(data, struct('layout', layout, 'filename', 'plotly-log-axes', 'fileopt', 'overwrite'));
plot_url = response.url
``````

#### Semilog Plot

``````% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

% Create some data
eb = 0:5;
SER = [0.1447 0.1112 0.0722 0.0438 0.0243 0.0122];
BER = [0.0753 0.0574 0.0370 0.0222 0.0122 0.0061];

% Create a y-axis semilog plot using the semilogy function
% Plot SER data in blue and BER data in red
fig = figure;
semilogy(eb, SER, 'bo-');
hold on;
semilogy(eb, BER, 'r^-');

% Turn on the grid
grid on;

% Add title and axis labels
title('Performance of Baseband QPSK');
xlabel('EbNo (dB)');
ylabel('SER and BER');

%--PLOTLY--%

% Strip MATLAB style by default!
response = fig2plotly(fig, 'filename', 'matlab-semi-logy-2');
plotly_url = response.url;
``````

#### Log-log Plot

``````% Learn about API authentication here: https://plot.ly/matlab/getting-started
% Find your api_key here: https://plot.ly/settings/api

zeta = [0.01 .02 0.05 0.1 .2 .5 1 ];
colors = ['r' 'g' 'b' 'c' 'm' 'y' 'k'];

w = logspace(-1, 1, 1000);

figure;
for i = 1:7
a = w.^2 - 1;
b = 2*w*zeta(i);
gain = sqrt(1./(a.^2 + b.^2));
loglog(w, gain, 'color', colors(i), 'linewidth', 2);
hold on;
end

% Set the axis limits
axis([0.1 10 0.01 100]);

% title and labels
title('|G|[omega]  vs omega');
xlabel('omega');
ylabel('|G|[omega]');

%--PLOTLY--%

% Strip MATLAB style by default!
response = fig2plotly(gcf, 'filename', 'matlab-log-log-line-2');
plotly_url = response.url;
``````