next up previous contents
Next: 2.1.3 Other 2-D plots Up: 2.1 Two-dimensional plots Previous: 2.1.1 Simple 2D plots   Contents

2.1.2 Log plots

Logarithmic plots can sometimes make it easier to plot certain kinds of data. For example, consider the function $y=bx^a$ where $a$ and $b$ are any real numbers. Try the following plot.
% Plot different polynomials
close all; clear all; % close all plot windows and clear all variables
x = 1:.1:100; % define the x-axis range for the data
y1 = 30*x;
y2 = x.^2;  % .^2 means raise each *individual element* of x to the power 2
y3 = 2*x.^2; 
y4 = x.^4/400; 
y5 = 1000*(x+1).^-3;
legend('line','quadratic1','quadratic2','quartic','inverse cubic',2)
Make sure you understand what each command does. One of the problems with this plot is that the scale of the data sets are so different that it is difficult to see the curves for the data that doesn't vary too much. One way to remedy this is to use a ``loglog'' plot. Try the following command,
legend('line','quadratic1','quadratic2','quartic','inverse cubic',4)
Now we can see each curve for individual data sets much better. But beyond that, what is the utility of plotting the data on a plot with logarithmically scaled axes? Try this. Look at the loglog plot and calculate the slope of each of the curves. How do the slopes of each of the curves correspond to the original function? In the previous example, we used a plot where both axes had a logarithmic scaling. This works well for functions of polynomials, but not for exponential functions like $e^x$. Try it and see for yourself. For exponential functions, try this.
% Plot exponential functions
close all; clear all;
t = 0:.1:10;
legend('e^t','e^{2t}','1/e^t',3) % Pay close attention to how the 
                                 % legend turns out--cool huh?
Again, most of the data is impossible to see because of the different scales of the different curves. So, rescale on the $y$-axis:
Now all the data can be seen seen simultaneously. Can you see the relationship of the slopes of the curves? One of the messages of this section is to use the appropriate kind of plot depending on the particular data you have--regular plots when the scale of the data sets are similar and don't vary widely, loglog plots for polynomial-type relationships, and semilog plots for exponential-type relationships.
next up previous contents
Next: 2.1.3 Other 2-D plots Up: 2.1 Two-dimensional plots Previous: 2.1.1 Simple 2D plots   Contents
Gus Hart 2005-01-28