Updated histogram2d example #2968

Closed
wants to merge 2 commits into
from

Projects

None yet

2 participants

@fkbreitl
Contributor
fkbreitl commented Feb 5, 2013

No description provided.

@njsmith njsmith commented on the diff Feb 5, 2013
numpy/lib/twodim_base.py
@@ -547,7 +547,7 @@ def histogram2d(x, y, bins=10, range=None, normed=False, weights=None):
An array of values ``w_i`` weighing each sample ``(x_i, y_i)``. Weights
are normalized to 1 if `normed` is True. If `normed` is False, the
values of the returned histogram are equal to the sum of the weights
- belonging to the samples falling into each bin.
+l belonging to the samples falling into each bin.
@njsmith njsmith commented on the diff Feb 5, 2013
numpy/lib/twodim_base.py
@@ -599,6 +601,23 @@ def histogram2d(x, y, bins=10, range=None, normed=False, weights=None):
<matplotlib.colorbar.Colorbar instance at ...>
>>> plt.show()
+
+ 2D-histogram with variable bin size:
+
+ >>>import numpy as np, matplotlib.pyplot as plt
+ x = np.random.normal(3, 2, 1000)
+ y = np.random.normal(3, 1, 1000)
+ yedges=xedges=[0,2,3,4,6]
+ H, yedges, xedges = np.histogram2d(y,x, bins=(yedges,xedges))
+ extent = [xedges[0], xedges[-1], yedges[-1], yedges[0]]
+ X,Y = np.meshgrid(xedges, yedges)
+ plt.pcolormesh(X, Y,H)
@njsmith
njsmith Feb 5, 2013 Member

Lots of PEP8 violations here -- there's no ration on spaces! ;-)

@njsmith njsmith commented on the diff Feb 5, 2013
numpy/lib/twodim_base.py
+ 2D-histogram with variable bin size:
+
+ >>>import numpy as np, matplotlib.pyplot as plt
+ x = np.random.normal(3, 2, 1000)
+ y = np.random.normal(3, 1, 1000)
+ yedges=xedges=[0,2,3,4,6]
+ H, yedges, xedges = np.histogram2d(y,x, bins=(yedges,xedges))
+ extent = [xedges[0], xedges[-1], yedges[-1], yedges[0]]
+ X,Y = np.meshgrid(xedges, yedges)
+ plt.pcolormesh(X, Y,H)
+ plt.colorbar()
+ plt.show()
+
+
+ For interpolated visulization matplotlib provides the NonUniformImage. See
+ http://matplotlib.org/examples/pylab_examples/image_nonuniform.html
@njsmith
njsmith Feb 5, 2013 Member

I'm a little wary about providing direct links like this (what happens next time matplotlib rearranges their docs?), and it seems out of place anyway -- wouldn't it be more useful to just continue the example using NonUniformImage to visualize the histogram2d output, instead of linking to a different example of using it?

@fkbreitl
fkbreitl Feb 5, 2013 Contributor

I can add a NonUniformImage example. Do you want me to do that?
But is there also a way to test how it will look at http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html ?
For example I would prefer to not use ">>>" because then one could copy and past the example directly form the doc page.
However, it seems like it is needed to separate code from comments.

@fkbreitl
fkbreitl Mar 25, 2013 Contributor

Can you tell me how to update and add figures on ttp://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html?highlight=histogram2d#numpy.histogram2d ?

@fkbreitl
Contributor

This pull request is now superseded by #3169 .

@fkbreitl fkbreitl closed this Mar 30, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment