histogram bug

>> The following minimal script reveals a rendering problem

    >> with >> displaying a histogram on a log vertical axis.

    > Has this been resolved yet? I'm running Matplotlib
    > 0.87.5-2.2 on Debian Unstable. I try to run the following
    > script:

    > from pylab import * hist(rand(100), 20) ax = gca()
    > ax.set_yscale('log') show()

You have to make sure your yaxis limits are strictly positive, eg

  ax.set_ylim(1e-3, 1e3)
  ax.set_yscale('log')

JDH

John Hunter wrote:

    >> >> The following minimal script reveals a rendering problem
    >> with >> displaying a histogram on a log vertical axis.

    > Has this been resolved yet? I'm running Matplotlib
    > 0.87.5-2.2 on Debian Unstable. I try to run the following
    > script:

    > from pylab import * hist(rand(100), 20) ax = gca()
    > ax.set_yscale('log') show()

You have to make sure your yaxis limits are strictly positive, eg

  ax.set_ylim(1e-3, 1e3)
  ax.set_yscale('log')

This doesn't work. The problem is that the patch objects are made first, and they start at y=0, so changing the y limits doesn't prevent the attempt to take the log of zero.

One solution would be to have the transform simply trap zero and negative inputs and change them, with or without a warning, to some very small positive value. This would do the right thing in the present case. In cases where a zero is used inadvertently and incorrectly, and where an exception really should be raised, it would not do so. Maybe this is a worthwhile tradeoff? This question has come up quite a few times, and it would be nice to stop that.

A solution for hist would be a kwarg to handle the log case. If hist is the only context in which this problem arises--that is, if all other cases are ones in which the zero has no business being there so an exception is appropriate--then adding log-handling to hist would be the way to go. But I suspect there are other cases, and we will keep getting this question. It's understandable, because the exception that gets triggered is not very informative.

Eric

···

JDH