how can a logscale be set for values that are already logged but too large to be exponentiated back to linear scale? example:
import matplotlib.pylab as plt
import numpy as np
def f_returns_verylarge_logs():
# some computation here that returns very small numbers on a log scale
# (meaning large negative numbers in log units)
log10_y = [3000, 3100, 3200]
return log10_y
ax1 = plt.subplot(2, 1, 1)
x = [1, 2, 3]
# y values are small, so it is no problem to keep them
# around in LINEAR scale
y = [50, 100, 200]
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y")
ax1.set(yscale="log")
ax2 = plt.subplot(2, 1, 2)
x = [1, 2, 3]
log_y = f_returns_verylarge_logs()
y = np.power(10., log_y)
plt.plot(x, y)
plt.xlabel("x")
plt.ylabel("y")
ax2.set(yscale="log")
plt.show()
this gives overflow error:
RuntimeWarning: overflow encountered in power
y = np.power(10., log_y)
the goal is to make the bottom plot work and look (in terms of yticks/labels) like the top without unlogging log_y
since it causes overflow.
a bad solution is to scale down the log values and then unlog them as in:
plt.figure()
scaled_log_y = np.array(log_y) / 100.
scaled_unlog_y = np.power(10., scaled_log_y)
plt.plot(x, scaled_unlog_y)
plt.gca().set(yscale="log")
plt.ylabel("y (units are wrong)")
plt.xlabel("x")
plt.show()
but this gives wrong units: for 3000, it says 10^30 instead of 10^3000.