Thursday, December 26, 2019

Logarithmic Plots (Log Plots)

A logarithmic plot is essentially a basic plot, but it is set on a logarithmic scale. The difference between this and a normal linear scale is that the intervals are set in order of their magnitude. We have two different types of log plots: the log-log plot and semi-log plot.

The log-log plot has logarithm scales on both the x and y axis. In matplotlib, this plot is identified by the following function: matplotlib.pyplot.loglog() . The semi-log plot, on the other hand, uses two different scales. It has a logarithmic scale on one axis and a linear scale on the other. They are identified by the following functions:

semilogx() for the x axis, and semilogy() for the y axis.

Straight lines in such plots are used to identify exponential laws. The code below represents data on transistor counts within a given range of years. We will use it to study the procedure for creating logarithmic plots:


import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
df = pd.read_csv('transcount.csv')
df = df.groupby('year').aggregate(np.mean)
years = df.index.values
counts = df['trans_count'].values
poly = np.polyfit(years, np.log(counts), deg=1)
print ("Poly", poly)
plt.semilogy(years, counts, 'o')
plt.semilogy(years, np.exp(np.polyval(poly, years)))
plt.show()


Step 1:

Build the data using the following functions:

poly = np.polyfit(years, np.log(counts), deg=1)
print "Poly", poly

Step 2:

From the data fit above, you should have a polynomial object. Based on the data available, you should have the polynomial coefficients arranged in descending order.

Step 3:

To study the polynomial created, use the NumPy function polyval() . Plot data and use the y axis semi-log function as shown:

plt.semilogy(years, counts, 'o')
plt.semilogy(years, np.exp(np.polyval(poly, years)))

Now run the program, you will get the following plot:

Also, Poly [ 3.61559210e-01 -7.05783195e+02] will be printed on the output window.

Share:

0 comments:

Post a Comment