Search code examples
pythonmatplotlibplotaxes

matplotlib bar plot for logarithmic y axis


I try to make a bar plot for a logarithmic y axis. Unfortunately, there are no bars anymore, if I set the y-axis to be logarithmic. What can I do to achieve this? Is there a possibility to set the reference point (default seems to be zero) in the bar-function?

My code is:

import matplotlib.pyplot as plt
import numpy as np


N=1000
sample=np.random.random_integers(1,10,N)
hist,bins=np.histogram(sample)


fig,ax=plt.subplots(figsize=(12,5),nrows=1,ncols=2,sharex=True,sharey=False)
ax[1].set_yscale("log")
ax[0].bar(bins[:-1],1.*hist/N,np.diff(bins))
ax[1].bar(bins[:-1],1.*hist/N,np.diff(bins))

plt.show()

The output: linear and log y axis

How to make the bars in the right panel?


Solution

  • Try updating maptlotlib. Works for me with version 1.4.2.

    enter image description here