I'd like to create a plt.hist2d
plot, but with a logarithmic y-axis. I first tried ax.set_yscale('log')
but then realized that the hist2d
function should already be aware of the logarithmic axis to choose the bins appropriately. Is there a way to do so?
import numpy as np
import matplotlib.pyplot as plt
# create some bogus data
n = 10000
x = np.random.randn(n)
y = np.log(np.abs(np.random.randn(n)))
plt.hist2d(x, y, bins=100) # create a logarithmic y axis?
# plt.gca().set_yscale('log') # doesn't work as intended
plt.show()