Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

example on numpy.histogram2d is broken (Trac #1830) #2423

Closed
numpy-gitbot opened this issue Oct 19, 2012 · 3 comments · Fixed by #4372
Closed

example on numpy.histogram2d is broken (Trac #1830) #2423

numpy-gitbot opened this issue Oct 19, 2012 · 3 comments · Fixed by #4372

Comments

@numpy-gitbot
Copy link

Original ticket http://projects.scipy.org/numpy/ticket/1830 on 2011-05-14 by @samtygier, assigned to @pv.

the matplotlib example in http://docs.scipy.org/doc/numpy/reference/generated/numpy.histogram2d.html plots the data with the axis the wrong way. i think this is mostly the fault of imshow working in backwards coordinates.

the lines should be:

extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.imshow(H.transpose(), extent=extent, interpolation='nearest', origin="lower")

test script (broken, as per numpy docs):

x = np.array([2,   2, -1, -1, -0.2])
y = np.array([1,-1.1,  1, -1,  0.5])
H, xedges, yedges = np.histogram2d(x,y, bins=(50, 50))
extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]
plt.imshow(H, extent=extent, interpolation='nearest')
plt.show()

test script (fixed):

x = np.array([2,   2, -1, -1, -0.2])
y = np.array([1,-1.1,  1, -1,  0.5])
H, xedges, yedges = np.histogram2d(x,y, bins=(50, 50))
extent = [xedges[0], xedges[-1], yedges[0], yedges[-1]]
plt.imshow(H.transpose(), extent=extent, interpolation='nearest', origin="lower")
plt.show()
@numpy-gitbot
Copy link
Author

@rgommers wrote on 2011-07-06

There's a second documentation (or implementation) issue. From email by Alex Burton:

When normed=True the documentation says that each bin will be divided by its area,
whereas in implementation it is divided by area and the sum of all bins.

This should be checked for numpy 2.0; also that the implementation is consistent with the new kw for histogram. See #2224.

@charris
Copy link
Member

charris commented Feb 26, 2014

The plot example was rewritten and looks fixed. The documentation issue originated in histogramdd, which also needs fixing.

@charris
Copy link
Member

charris commented Feb 26, 2014

Note that the density keyword is missing from both histogram2d and histogramdd.

charris added a commit to charris/numpy that referenced this issue Feb 26, 2014
The documentation misrepresented what happened, leaving out division
by the total number of sample points.

Also run spellcheck over function_base.py and twodim_base.py and break
some long lines.

Closes numpy#2423.
charris referenced this issue Mar 1, 2014
DOC: Fix documentation of normed keyword in histogram2d and histogramdd.
charris added a commit to charris/numpy that referenced this issue Mar 1, 2014
The documentation misrepresented what happened, leaving out division
by the total number of sample points.

Also run spellcheck over function_base.py and twodim_base.py and break
some long lines.

Closes numpy#2423.
charris added a commit to charris/numpy that referenced this issue Mar 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants