Histogram compatibility with numpy 7364#7856
Histogram compatibility with numpy 7364#7856chelseatroy wants to merge 6 commits intomatplotlib:masterfrom
Conversation
determinism_tex.svg
Outdated
| @@ -0,0 +1,29 @@ | |||
| <?xml version="1.0" encoding="utf-8" standalone="no"?> | |||
There was a problem hiding this comment.
Please rebase and remove this file entirely.
There was a problem hiding this comment.
Hi @QuLogic!
Thanks for the quick response. I rebased, but my changes are up to date with the current remote. The contents of determinism_tex.svg appear to be tested in test_backend_svg.py (line 204). Would you still like me to remove it?
There was a problem hiding this comment.
This was added in your first commit. You'll need to rebase and edit the first commit to remove the file.
|
|
||
| @_preprocess_data(replace_names=["x", 'weights'], label_namer="x") | ||
| def hist(self, x, bins=None, range=None, normed=False, weights=None, | ||
| def hist(self, x, bins=None, range=None, density=None, weights=None, |
There was a problem hiding this comment.
Changing the order is probably not a good idea, for backwards compatibility's sake, even though people really shouldn't be expecting order-only arguments to work this far in.
There was a problem hiding this comment.
Hi @QuLogic!
My understanding is that if a user is expecting order-only arguments to work this far in, then their argument will just take the name density instead of normed now. And since the name density is meant, in this change, to actually replace normed, the code will still be backward compatible. If the developer specifically named it normed, then the fact that it's named allows it to work even though normed is at the end now.
Please let me know if this is inaccurate.
There was a problem hiding this comment.
I think this is safe to do. If people are using positional it just works, if they are using keyword it still just works. By putting this here we make it clearer which the preferred name is.
lib/matplotlib/axes/_axes.py
Outdated
| Default is ``None`` | ||
|
|
||
| normed : boolean, optional | ||
| normed or density : boolean, optional |
There was a problem hiding this comment.
suggest putting 'density' first as that will (eventually) be the preferred name.
lib/matplotlib/axes/_axes.py
Outdated
| An array of weights, of the same shape as `x`. Each value in `x` | ||
| only contributes its associated weight towards the bin count | ||
| (instead of 1). If `normed` is True, the weights are normalized, | ||
| (instead of 1). If `normed` and/or 'density' is True, the weights are normalized, |
There was a problem hiding this comment.
Probably too long; wrap at 79 characters.
lib/matplotlib/axes/_axes.py
Outdated
| If `True`, then a histogram is computed where each bin gives the | ||
| counts in that bin plus all bins for smaller values. The last bin | ||
| gives the total number of datapoints. If `normed` is also `True` | ||
| gives the total number of datapoints. If `normed` and/or 'density' is also `True` |
There was a problem hiding this comment.
Probably too long; wrap at 79 characters.
lib/matplotlib/axes/_axes.py
Outdated
| """ | ||
|
|
||
| # This sets the density variable, if necessary, to its predecessor, 'normed.' | ||
| if density != None and normed != None and density != normed: |
lib/matplotlib/axes/_axes.py
Outdated
| # This sets the density variable, if necessary, to its predecessor, 'normed.' | ||
| if density != None and normed != None and density != normed: | ||
| raise ValueError('The density and normed arguments represent the same concept. Please set only one of them, or set them to the same value.') | ||
| elif normed != None and density == None: |
lib/matplotlib/tests/test_axes.py
Outdated
| ax = fig.add_subplot(111) | ||
| ax.hist((d1, d2), stacked=True, normed=True) | ||
|
|
||
| @image_comparison(baseline_images=['hist_stacked_normed']) |
| noverlap=noverlap, pad_to=pad_to, sides='onesided', | ||
| mode='phase', scale='dB') | ||
|
|
||
| with pytest.raises(ValueError): |
There was a problem hiding this comment.
@QuLogic it shouldn't have been. My mistake—good catch!
lib/matplotlib/tests/test_axes.py
Outdated
| d1 = np.linspace(1, 3, 20) | ||
| d2 = np.linspace(0, 10, 50) | ||
| fig = plt.figure() | ||
| ax = fig.add_subplot(111) |
|
Mostly minor formatting things; it seems to make sense otherwise. |
|
If that makes your life easier, we are using the tool |
| set, then that value will be used. If neither are set, then the args | ||
| will be treated as 'False.' | ||
|
|
||
| If both are set to different things, the hist function raises an |
There was a problem hiding this comment.
I suggest 'if both are set, raise' even if they are the same.
There was a problem hiding this comment.
Change made and pushed.
There was a problem hiding this comment.
The docs are out of sync with the code.
|
Pushed several changes as per @QuLogic's observations and suggestions! |
bdcaab5 to
932e4c8
Compare
|
Force pushed to remove determinism_tex.svg from 3 commits back. |
|
There are still a few PEP 8 violations that are causing the tests to fail (https://travis-ci.org/matplotlib/matplotlib/jobs/193148586#L1777), would it be okay to fix them? They look like they are all lines that are longer than 79 characters, which is the maximum allowed line length. |
lib/matplotlib/axes/_axes.py
Outdated
| only contributes its associated weight towards the bin count | ||
| (instead of 1). If `normed` is True, the weights are normalized, | ||
| so that the integral of the density over the range remains 1. | ||
| (instead of 1). If `normed` and/or 'density' is True, |
lib/matplotlib/axes/_axes.py
Outdated
| If `cumulative` evaluates to less than 0 (e.g., -1), the direction | ||
| of accumulation is reversed. In this case, if `normed` is also | ||
| `True`, then the histogram is normalized such that the first bin | ||
| gives the total number of datapoints. If `normed` and/or 'density' |
lib/matplotlib/axes/_axes.py
Outdated
| ------- | ||
| n : array or list of arrays | ||
| The values of the histogram bins. See **normed** and **weights** | ||
| The values of the histogram bins. See **normed or density** and **weights** |
There was a problem hiding this comment.
This line is likely too long and needs to be wrapped.
lib/matplotlib/tests/test_axes.py
Outdated
| ax.hist((d1, d2), stacked=True, normed=True) | ||
|
|
||
|
|
||
| @image_comparison(baseline_images=['hist_stacked_normed']) |
There was a problem hiding this comment.
If you are going to add an image test you also need to commit the baseline images.
If this adds coverage we don't have other wise, the images (or at least the png) should be added; if not, just drop the decorator.
|
@chelseatroy ping on this. |
|
Hi @tacaswell. Just saw this. I guess for some reason I didn't receive a notification about your ping on this PR. If this still hasn't been done, I can make the changes this week...though I suspect someone has beat me to it. |
|
@tacaswell I guess I'm pretty lost as to what to do from here. All the build checks are failing, I don't really understand why, I basically just changed the character width of some comments. |
|
Presumably because of other changes since the last time you added a commit, there are conflicts so that your changes no longer merge cleanly. The "Resolve conflicts" button shows them nicely, and it looks like they will be easy to resolve. |
Looks like there are 2 formatting issues. |
| elif normed is None and density is None: | ||
| density = False | ||
|
|
||
| def _normalize_input(inp, ename='input'): |
There was a problem hiding this comment.
I am confused by this? Did this come from the merge?
|
Hi @chelseatroy, 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. |
The hist function should now work with either 'normed' or 'density' defined.
If neither are defined, default is 'False.'
If both are defined as different things, the function raises an error.
Some tests added, and comment documentation updated, to reflect the changes.