Search code examples
pythonmatplotlibplotaxes

matplotlib bar plot adjust bar direction


I want to start the bars from the bottom. How can I change the starting point from zero to e.g. -2 ?

My code:

import matplotlib.pyplot as plt
import numpy as np


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

plt.bar(bins[:-1],np.log10(1.*hist/N),np.diff(bins))

plt.show()

Output: enter image description here


Solution

  • Try This:

    plt.bar(bins[:-1],abs(np.log10(1.*hist/N)),np.diff(bins))