Skip to content

hist(..., histtype='step') does not set ylim properly. #2061

Closed

Description

@tkf

Checked with the latest version from master (d5071f4).

import numpy
import pylab

x = numpy.array(
      [ 94,  95,  96,  98,  84, 104,  99,  88,  80,  90,  99,  95,  89,
        88,  94,  99,  99,  91, 100,  86, 102,  85,  84,  95,  87,  87,
       106, 109,  97,  97, 106,  93,  90,  91,  95,  93,  81,  93, 103,
        82,  94,  89, 113,  93,  95, 103,  99,  99,  93, 103,  87,  94,
        96, 104,  88,  98,  89, 117,  88,  87,  97,  91,  84,  90,  98,
        90, 100,  92, 102,  89, 104, 104,  92,  96,  88,  97, 105, 106,
       104, 105,  88,  93, 112,  82, 102,  81,  80,  86, 100, 101,  93,
        93,  91,  99,  90, 100,  93,  96,  99,  99])
pylab.hist(x, histtype='step')
pylab.savefig('fig.png')

fig

It failed to show the lower y values. If you set ymin=0, you can see it:

pylab.ylim(ymin=0)
pylab.savefig('fig2.png')

fig2

Activity

  1. mdboom commented on May 24, 2013

    @mdboom
    Member

    Marking as 1.3.x blocker -- hopefully the fix is simple an obvious, otherwise it might not make the cutoff, of course.

  2. dhyams commented on May 24, 2013

    @dhyams
    Contributor

    I can confirm that if you stick in a relim() call right at the end of Axes.hist(), it fixes this bug:

        self.set_autoscalex_on(_saved_autoscalex)
        self.set_autoscaley_on(_saved_autoscaley)
        self.relim()    #<------------------HERE
        self.autoscale_view()
    
        if nx == 1:
            return n[0], bins, cbook.silent_list('Patch', patches[0])
        else:
            return n, bins, cbook.silent_list('Lists of Patches', patches)
    

    What I cannot confirm is that this is the best way to fix this bug. I'm not entirely clear why there is funny business going on with flipping autoscaling on and off in the hist() routine. I guess there is some updating of self.dataLim that gets missed out on, because of autoscaling being turned on and off during hist()?

    image

  3. mdboom commented on May 29, 2013

    @mdboom
    Member

    Fixed by #2082.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions