Created
December 13, 2018 14:39
-
-
Save kingjr/abfb39f0deb5c80c91d3554f731eed9c to your computer and use it in GitHub Desktop.
plot log log axis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import numpy as np | |
x = np.linspace(-10, 10) | |
y = np.cos(x) / 2. + .5 | |
z = np.sin(x) / 20. + .5 | |
def jr_transform(x, baseline=.50, scaling=100): | |
x = x - baseline | |
above = np.log(scaling*x*(x>0)+1) | |
below = np.log(-scaling*x*(x<=0)+1) | |
x = np.nan_to_num(above) - np.nan_to_num(below) | |
return x / 2. + baseline | |
fig, (ax, ax1) = plt.subplots(1, 2) | |
ax.plot(x, y, color='C0') | |
ax.plot(x, z, color='C1') | |
yticks = np.linspace(0, 1, 11) | |
ax.set_yticks(yticks) | |
ax.set_yticklabels(['.%.2f' % i for i in yticks]) | |
ax.set_title('original') | |
ax1.plot(x, jr_transform(y), color='C0') | |
ax1.plot(x, jr_transform(z), color='C1') | |
ax1.set_yticks(jr_transform(yticks)) | |
ax1.set_yticklabels(['.%.2f' % i for i in yticks]) | |
ax1.set_title('log') | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment