Logarithmic Plots

The functions semilgox() and semilogy() are used to plot the x-axis and y-axis in a logarithmic scale, respectively. Logarithmic plots of type semilogy() are common when plotting power or intensity values, for example, those of the Richter magnitude scale, which measures seismic energy. Likewise, measurements of quantities used with frequencies, for example, are commonly plotted on a logarithmic x-scale denoting octaves and decades. There's also the option of using a loglog() plot, which means both x-axis and y-axis are logarithmic. This is the case in Bode plots, common in engineering fields.

All three functions, semilogx(), semilogy(), and loglog(), can be modified with arguments similar to those presented with the plot() function.

The function logspace(start, stop, numpoints=50, endpoint=True, base=10.0) can be useful in creating a range of values to be plot with the preceding functions. The start and stop values are the exponent values. logspace() generates logarithmically spaced values between 10**start and 10**stop. You can decide whether the end value, 10**end, is returned by specifying endpoint=True. If you'd like a base other than 10, set base to the value you require.

array([ 2.00000000e+01, 2.00000000e+02, 2.00000000e+03,

2.00000000e+04, 2.00000000e+05]) >>> semilogx(I, [20, 19, 8, 2, 2], '+-') »> grid()

>>> title('Logarithmic plot, semilogx()') >>> xlabel('Frequency [Hz]') >>> ylabel('Amplitude [dB]')

Figure 6-12 shows the results of the preceding example.

Logarithmic plot, semilogx()

Logarithmic plot, semilogx()

Frequency [Hz]

Figure 6-12. Logarithmic plot iol io2 io3 ioa io5 io6

Frequency [Hz]

Figure 6-12. Logarithmic plot

Notice that when plotting with semilogx(), semilogy(), and loglog(), the labels are the original values, not the logarithms of the values. If you'd like to print the logarithmic values, you should probably use a regular plot() function with log() or logl0() of the values. This is useful, for example, in estimating the energy in decibels (dB):

»> plot(db(array([l000, 980, 970, 400, 30, 2, 1, l])))

Was this article helpful?

0 0

Post a comment