0

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()
flawr
  • 10,814
  • 3
  • 41
  • 71
  • What about first setting the log scale (`plt.yscale('log')`) and then calling seaborn's `sns.histplot(x=x, y=y)`? – JohanC May 24 '23 at 12:21

0 Answers0