Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8487321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:12:11+00:00 2026-06-10T21:12:11+00:00

I’m trying to draw part of a histogram using matplotlib. Instead of drawing the

  • 0

I’m trying to draw part of a histogram using matplotlib.

Instead of drawing the whole histogram which has a lot of outliers and large values I want to focus on just a small part. The original histogram looks like this:

hist(data, bins=arange(data.min(), data.max(), 1000), normed=1, cumulative=False)
plt.ylabel("PDF")

enter image description here

And after focusing it looks like this:

hist(data, bins=arange(0, 121, 1), normed=1, cumulative=False)
plt.ylabel("PDF")

enter image description here

Notice that the last bin is stretched and worst of all the Y ticks are scaled so that the sum is exactly 1 (so points out of the current range are not taken into account at all)

I know that I can achieve what I want by drawing the histogram over the whole possible range and then restricting the axis to the part I’m interested in, but it wastes a lot of time calculating bins that I won’t use/see anyway.

hist(btsd-40, bins=arange(btsd.min(), btsd.max(), 1), normed=1, cumulative=False)
axis([0,120,0,0.0025])

enter image description here

Is there a fast and easy way to draw just the focused region but still get the Y scale correct?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:12:12+00:00Added an answer on June 10, 2026 at 9:12 pm

    In order to plot a subset of the histogram, I don’t think you can get around to calculating the whole histogram.

    Have you tried computing the histogram with numpy.histogram and then plotting a region using pylab.plot or something? I.e.

    import numpy as np
    import pylab as plt
    
    data = np.random.normal(size=10000)*10000
    
    plt.figure(0)
    plt.hist(data, bins=np.arange(data.min(), data.max(), 1000))
    
    plt.figure(1)
    hist1 = np.histogram(data, bins=np.arange(data.min(), data.max(), 1000))
    plt.bar(hist1[1][:-1], hist1[0], width=1000)
    
    plt.figure(2)
    hist2 = np.histogram(data, bins=np.arange(data.min(), data.max(), 200))
    mask = (hist2[1][:-1] < 20000) * (hist2[1][:-1] > 0)
    plt.bar(hist2[1][mask], hist2[0][mask], width=200)
    

    Original histogram:
    Original histogram

    Histogram calculated manually:
    Histogram calculated manually

    Histogram calculated manually, cropped:
    Histogram calculated manually, cropped
    (N.B.: values are smaller because bins are narrower)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.