Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

FIX: Introduced new keyword 'density' in the hist function#8408

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
moboehle wants to merge4 commits intomatplotlib:masterfrommoboehle:bccn_hist

Conversation

moboehle
Copy link
Contributor

Introduced new keyword 'density' in the hist function to be consistent with numpy.

This pull request closes issue#7364. Contrary to what was suggested in the comments, no error is raised in the case that both keywords density and normed are used. If neither are defined, default is 'False'.

@QuLogic
Copy link
Member

@tacaswell I thought we had a PR for this; did it not get merged?

@phobson
Copy link
Member

@QuLogic see#7856

@moboehle
Copy link
ContributorAuthor

Sorry, I didn't see that there was a PR already, since it did not reference the issue.
The solutions to introducing 'density' as a new keyword are almost identical. However, as@tacaswell pointed out, we can pass the keyword density to np.histogram and delete the additional normalization in the hist function, in order to simplify the code. This is the main difference between the two fixes. Furthermore, in the current version of this PR, no error is raised if 'normed' and 'density' are both used but not contradicting. I think as long as there is no ambiguity in the input, no error should be raised, as it would cause an unnecessary inconvenience to the user.

@@ -6220,7 +6225,7 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
if cbook.is_numlike(cumulative) and cumulative < 0:
slc = slice(None, None, -1)

ifnormed:
ifdensity:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Looks like this path is never tested. Could you add a test that uses thedensity option?

dstansby reacted with thumbs up emoji
@@ -6132,6 +6135,10 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
if histtype == 'barstacked' and not stacked:
stacked = True

if density is not None and normed is not None and normed != density:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Add a test to check this

@@ -6132,6 +6135,10 @@ def hist(self, x, bins=None, range=None, normed=False, weights=None,
if histtype == 'barstacked' and not stacked:
stacked = True

if density is not None and normed is not None and normed != density:
raise ValueError("kwargs density and normed cannot have different\
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Minor style comment. Can you do:

raiseValueError("kwargs density and normed cannot have different ""values. Use density only, since normed will be deprecated.")

@phobsonphobson added this to the2.1 (next point release) milestoneMar 31, 2017
@tacaswell
Copy link
Member

Thanks for your work on this!

I definitely think it should raise if both kwargs are passed. If the uses passes in both, then they must be passed as identical values (so we do not have to document and people do not have understand the precedence rules). This can lead to very brittle code, will just move the frustration / debugging to a later time (when they two values get out of sync), and does not actually help improve the clarity.

@moboehle Are you comfortable enough with git to merge the two pull requests together?

@moboehle
Copy link
ContributorAuthor

@phobson Thanks for your feedback, I added some tests now.

@tacaswell You are right, allowing to set both 'normed' and 'density' could lead to odd behavior, I updated this now. I would be happy to merge the pull requests together, but I am not quite sure how to go about this.

Copy link
Member

@dstansbydstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This looks good - just need to get rid of the changes to the autogenerated file.

I also can't see any tests in the diff?

bottom=None, histtype='bar', align='mid', orientation='vertical',
rwidth=None, log=False, color=None, label=None, stacked=False,
hold=None, data=None, **kwargs):
def hist(x, bins=None, range=None, density=None, normed=None, weights=None,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

lib/matplotlib/pyplot.py is an autogenerated file, so these changes will need to be reverted.

@tacaswell
Copy link
Member

#7856 has a test (that needs an image committed).

@moboehle I suggest you do the following:

git checkout bccn_hist # just to be safe# add a remotegit remote add chelseatroy https://github.com/chelseatroy/matplotlib.git# update your remotesgit remote updategit merge chelseatroy/histogram_compatibility_with_numpy_7364

You will probably have to clean up some conflicts, but then commit and push everything back to your branch.

You will need commit the test image results as well.

If you need help jump intohttps://gitter.im/matplotlib/matplotlib

@QuLogic
Copy link
Member

Ping@moboehle.

@dstansby
Copy link
Member

Hi@moboehle , thanks for the PR! Since there were two PRs I have merged them together with a few fixes and put them in#8993 - you will still be attributed to the work when it gets merged though.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@phobsonphobsonphobson left review comments

@dstansbydstansbydstansby requested changes

Assignees
No one assigned
Projects
None yet
Milestone
v2.1
Development

Successfully merging this pull request may close these issues.

5 participants
@moboehle@QuLogic@phobson@tacaswell@dstansby

[8]ページ先頭

©2009-2025 Movatter.jp