## Re: [Matplotlib-users] manipulating histogram data from hist function

 Re: [Matplotlib-users] manipulating histogram data from hist function From: Paul Ivanov - 2010-12-28 02:39:51 Attachments: Message as HTML ```Philippe Piot, on 2010-12-27 13:58, wrote: > 1/ When executing the above script, I also display the histograms > generated when invoking "hist" (I tried to make this line tranparaent > by using alpha=0 but it did not work). Hi Philippe, welcome to matplotlib - I think what you really want to do is just use numpy's histogram function, and then plot the result. This is actually the function matplotlib's hist uses behind the scenes. > 2/ can I directly manipulate the data within an histogram to > arbitrarily offset the histogram? Once you get the histogram using numpy, you can plot it in in any way you want. Here's a small example: import numpy as np import matplotlib.pyplot as plt h,edges = np.histogram(np.random.randn(1000)) plt.bar(edges[:-1],h, width=edges[1]-edges[0]) plt.bar(edges[:-1]-10,h, width=edges[1]-edges[0]) #offset plt.step(edges[1:],h) # plot as step lines instead of bars plt.step(edges[1:]+10,h) # same as above, with an offset best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 ```

 [Matplotlib-users] manipulating histogram data from hist function From: Philippe Piot - 2010-12-27 19:59:05 ```Hello All, I am trying to produce a 2D density plot of a distribution and would like to show the associated projection computed as histogram. I need to perform an operation on the histogram to offset them. Right now I am doing this: # plot my 2D distribution hexbin(x,y, cmap=cm.jet, bins='log',gridsize=151) # compute the associated projection (I would like not to show them but use the hist to get the histrgram data) ny, binsy, histoy = hist(y, bins=121, normed=1, histtype='step', color='white') nx, binsx, histox = hist(x, bins=121, normed=1, histtype='step', orientation='horizontal', color='white', alpha=0.0) # manipulate the histogram data Nbinsx = binsx[:-1] Nbinsy = binsy[:-1] # plot offset histogram plot (Nbinsx,nx-2.5,color='white') plot (ny-2.5, Nbinsy,color='white') I have two questions (my apology I am a novice with matplotlib): 1/ When executing the above script, I also display the histograms generated when invoking "hist" (I tried to make this line tranparaent by using alpha=0 but it did not work). 2/ can I directly manipulate the data within an histogram to arbitrarily offset the histogram? Thank you for any suggestion. Best, -- Philippe. ```
 Re: [Matplotlib-users] manipulating histogram data from hist function From: Paul Ivanov - 2010-12-28 02:39:51 Attachments: Message as HTML ```Philippe Piot, on 2010-12-27 13:58, wrote: > 1/ When executing the above script, I also display the histograms > generated when invoking "hist" (I tried to make this line tranparaent > by using alpha=0 but it did not work). Hi Philippe, welcome to matplotlib - I think what you really want to do is just use numpy's histogram function, and then plot the result. This is actually the function matplotlib's hist uses behind the scenes. > 2/ can I directly manipulate the data within an histogram to > arbitrarily offset the histogram? Once you get the histogram using numpy, you can plot it in in any way you want. Here's a small example: import numpy as np import matplotlib.pyplot as plt h,edges = np.histogram(np.random.randn(1000)) plt.bar(edges[:-1],h, width=edges[1]-edges[0]) plt.bar(edges[:-1]-10,h, width=edges[1]-edges[0]) #offset plt.step(edges[1:],h) # plot as step lines instead of bars plt.step(edges[1:]+10,h) # same as above, with an offset best, -- Paul Ivanov 314 address only used for lists, off-list direct email at: http://pirsquared.org | GPG/PGP key id: 0x0F3E28F7 ```