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

  • Home
  • SEARCH
  • 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 3429736
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T07:07:07+00:00 2026-05-18T07:07:07+00:00

I have the following problem. I have a 2D array of N pairs. e.g:

  • 0

I have the following problem. I have a 2D array of N pairs. e.g: x = [[5,2],[10,5],[3,2],…]
(so a set of arrays a = [5,10,3,…] and b= [2,5,2,…]
The first column (a) corresponds to the number of items.
The second column (b) is time taken to obtain the items in column (a).

I want to plot a cumulative histogram of the total time taken to obtain the items.
The x axis will be in bins of array (a), and the y axis should be the sum of the times from array (b) for each bin of (a). i.e. I want to plot “Nr of items”-vs-“Total time to obtain (cumulative)” as opposed to the default “Nr of items”-vs-“Nr of instances in array (a)”

I hope that makes some sense.

  • 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-05-18T07:07:07+00:00Added an answer on May 18, 2026 at 7:07 am

    I tend to be a big fan of matplotlib (http://matplotlib.sourceforge.net/) these days. It’s got lots of built-in functionality for just about every type of plotting you’ll want to do.

    Here are a whole bunch of examples on how to create histograms (with images and source code available):

    http://matplotlib.sourceforge.net/examples/pylab_examples/histogram_demo_extended.html

    Here’s the documentation of the hist() function itself:

    http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.hist

    If that’s not quite what you want, you can browse the gallery and look for a more fitting plot type. They all have source code available:

    http://matplotlib.sourceforge.net/gallery.html

    Hopefully that’s what you’re looking for.


    Adding an example. So is this more along the lines of what you’re looking for? (Not a histogram really anymore):

    If so, here’s the code to generate it (x is the sample input):

    from pylab import *
    
    x = [[5,2],[10,5],[3,2],[5,99],[10,22],[3,15],[4,30]]
    a,b = zip(*x) #Unzip x into a & b as per your example
    
    #Make a dictionary where the key is the item from a and the value
    #is the sum of all the corresponding entries in b
    sums = {}
    for i in range(0,len(a)):
        sums[a[i]] = b[i] if not a[i] in sums else sums[a[i]] + b[i]
    
    #Plot it
    ylabel('Bins')
    xlabel('Total Times')
    barh(sums.keys(),sums.values(),align='center')
    show()
    

    If not, I will give up and admit I’m still not quite understanding what you want. Good luck!

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

Sidebar

Related Questions

i have following problem from book introduction algorithm second edition by MIT university problem
I have the following problem. I have an array of bytes that I want
I have the following problem: In Rails I have two Objects: Categories and Items
I have the following problem: There is an array that consists of 6 numbers,
I have following problem to solve. As as input i have 2 decimal arrays.
I have the following problem i need in array 3 the languages names not
I got the following problem: I have an array of char pointers char *opts[]
I have the following problem: I have this multi-level array (nested array) which contains
I have following problem: I have built a tabbar application with 4 tabs. I
I have following problem, Code: String a=Yeahh, I have no a idea what's happening

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.