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.
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 (
xis the sample input):If not, I will give up and admit I’m still not quite understanding what you want. Good luck!