## Python – plotting with different scales

Ever wondered whether the data set you are dealing with is governed by a power law, or by some other distribution…?

A quick and easy way to assess whether your data conforms to a power law is to plot the data on a log-log scale, that is, where both the x-axis and y-axis have logaritmic scales. If your data are power law-based, then the plot will be a (approximation of)a straight line.

On the other hand, if you suspect your data conform to an exponential distribution, you can try the lin-log, or ‘semi-log‘ plot: if the data indeed are exponential, then the semi-log plot will produce a straight line.

Below Python code to produce the graphs above:

import matplotlib.pyplot as plt
import numpy as np

def powerfunc(x):
return x * x

def expfunc(x):
return np.exp(x*5)

xvalues = np.linspace(0.0,1.0,100)

ypower = np.zeros(len(xvalues))
yexp = np.zeros(len(xvalues))

ypower = powerfunc(xvalues)
yexp = expfunc(xvalues)

fig = plt.figure(figsize=(13.5, 6.0), dpi=100)

ax = plt.subplot(2,3,1)
plt.title('power function lin-lin scale')
plt.plot(xvalues,ypower,label='y=x*x')
plt.legend(loc='upper left')

plt.subplot(2,3,2)
plt.title('power function lin-log scale')
plt.yscale('log')
plt.plot(xvalues,ypower,label='y=x*x')
plt.legend(loc='upper left')

plt.subplot(2,3,3)
plt.title('power function log-log scale')
plt.xscale('log')
plt.yscale('log')
plt.plot(xvalues,ypower,label='y=x*x')
plt.legend(loc='upper left')

plt.subplot(2,3,4)
plt.title('exp function lin-lin scale')
plt.plot(xvalues,yexp,label='y=exp(5x)')
plt.legend(loc='upper left')

plt.subplot(2,3,5)
plt.title('exp function lin-log scale')
plt.yscale('log')
plt.plot(xvalues,yexp,label='y=exp(5x)')
plt.legend(loc='upper left')

plt.subplot(2,3,6)
plt.title('exp function log-log scale')
plt.xscale('log')
plt.yscale('log')
plt.plot(xvalues,yexp,label='y=exp(5x)')
plt.legend(loc='upper left')

plt.tight_layout()
plt.show()