1

This is a combination of this thread on multiple histograms, and this thread on a logarithmic scales.

I am trying to have two (or more) histograms in a plot with a logarithmic x-scale, using this code: (with some external lists)

import numpy
import matplotlib.pyplot as plt

plt.hist([capacity_list, capacity_list2], np.logspace(-1,4,11))
plt.gca().set_xscale("log")
plt.show()

It works in principle; my only problem is that the logarithmic scale also seems to affect the bin width of the histograms and so one if them always has shorter bins, which doesn't look nice:

two histograms with logarithmic x-axis

Does anybody know how to fix that?

Community
  • 1
  • 1
Arjay7891
  • 11
  • 2
  • 1
    I think you would be better off using one of the other styles of histogram (like `step`) as the offset and shrinking of the bars is actually very misleading in this case. The 'stacked' variaty of histograms might also be good here. – tacaswell Jul 06 '16 at 23:53
  • Have you tried using `np.histogram` and then plotting a bar plot ? – hashcode55 Jul 07 '16 at 07:20
  • @tcaswell using step is a good idea, that also works for what I want. Stacked is not so good since it makes it harder to compare the sizes of the bins visually. – Arjay7891 Jul 07 '16 at 17:47
  • @hashcode55 I looked into it using this [link](http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram.html) documentation, but couldn't get it to work. Also it says that matplotlib passes the arguments for histograms to np.histogram anyways, so not sure it would make a difference – Arjay7891 Jul 07 '16 at 17:49

0 Answers0