How to zoom in a histogram in seaborn/matplotlib?

10,753

Looks like the data would be better viewed on a logarithmic scale. On your matplotlib plot axis, ax, use:

ax.set_yscale('log')
Share:
10,753

Related videos on Youtube

Piyush
Author by

Piyush

Live and let live! SOreadytohelp

Updated on June 04, 2022

Comments

  • Piyush
    Piyush almost 2 years

    I produced a histogram which looks something like this:

    enter image description here

    Code that I used to produce this plot:

    sns.countplot(table.column_name)
    

    As you can notice, the entire histogram gets clustered at the left end due to uneven distribution of data.

    How do I zoom in at the left end?

    One way that I tried and it gave me a marginally better result was :

    plt.xlim(0,25)
    

    Is there a better way to do this?

    • juanpa.arrivillaga
      juanpa.arrivillaga over 7 years
      What doesn't work for you with plt.xlim(0,25)?
    • estebanpdl
      estebanpdl over 7 years
      Did you tried range as a parameter in plt.hits(). For example: plt.hist(..., ..., range(0, 25)
    • Piyush
      Piyush over 7 years
      @juanpa.arrivillaga : End up losing data for all x > 25. Just checking if there is a better way
    • juanpa.arrivillaga
      juanpa.arrivillaga over 7 years
      You're going to end up losing data one way or another if you zoom in, no?
    • Vincenzooo
      Vincenzooo over 7 years
      what do you mean by "a better way"? Why are you not satisfied with that? If you just want to zoom the plot, this is the way to do it. If you want to change the intervals on which data are calculated, you need to use range as indicated above (even if there are 2 syntax errors in the comment).