Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ENH: plotting methods can unpack labeled data #4829

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

Merged
merged 63 commits into from
Sep 13, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
367b68f
ENH: Make implicit x in plot pandas aware
tacaswell Jul 26, 2015
34b879a
ENH: plotting methods can unpack labeled data
tacaswell Jul 25, 2015
9f145cc
ENH: add white-list of args/kwargs to relpace
tacaswell Jul 26, 2015
a1c9c34
MNT: remove unused rcparam
tacaswell Jul 26, 2015
1e04469
MNT: python 2.6 does not support set literals
tacaswell Jul 27, 2015
d6e177f
ENH: pass at decorator which extracts a label
tacaswell Jul 28, 2015
8a77f90
FIX: fix typo, slightly rename variables
tacaswell Jul 29, 2015
dbd3445
FIX: fix yet more typos
tacaswell Jul 29, 2015
1ae230d
ENH: New version of unpack_labeled_data
jankatins Jul 30, 2015
ab6d39c
FIX: Update .gitignore for pycharm project files
jankatins Jul 30, 2015
6e29d39
ENH: proper arguments for labeled data decorator, part 1
jankatins Aug 2, 2015
f488bc7
ENH: let unpack_labeled_data handle var-length *args
jankatins Aug 2, 2015
1543cde
ENH: proper arguments for labeled data decorator, part 2
jankatins Aug 2, 2015
f4eea6e
FIX: handle 'enough' information about arg names in unpack_labeled_data
jankatins Aug 2, 2015
c4a6044
FIX: unbreak another corner case in unpack_labeled_data
jankatins Aug 3, 2015
4d1ffb8
FIX: fix unwarranted label argument for pie() with unpack_labeled_data
jankatins Aug 3, 2015
c78bb92
FIX: decorate funcs which take 2d data
jankatins Aug 3, 2015
d3331ca
ENH: change 'label_namer' default to None
jankatins Aug 3, 2015
ea3e22d
PEP8: fix some of the PEP8 problems in new code
jankatins Aug 3, 2015
3273673
PEP8: line wrapping fixes
tacaswell Aug 3, 2015
346a014
PEP8: more line length fixes
jankatins Aug 4, 2015
85d0e74
ENH: extract label from input data in `plot`
tacaswell Aug 7, 2015
1f36892
MNT: add a comment about label_naming in plot(...)
jankatins Aug 8, 2015
8dbb2cc
ENH: Append docs in @unpack_labeled_data
jankatins Aug 9, 2015
c768f0d
ENH: accept a function for arg names in @unpack_labeled_data
jankatins Aug 9, 2015
385b8e3
ENH: use the new 'names via function' for @unpack_labeled_data
jankatins Aug 9, 2015
812f74f
FIX: rename test file for @unpack_labeled_data
jankatins Aug 9, 2015
2194e80
FIX: assert_regexp_matches is only in py2.7
jankatins Aug 13, 2015
52d23c9
TST: workaround for unicode prefix in test matching
jankatins Aug 13, 2015
8aa800b
PEP8: line wrapping, spacing
jankatins Aug 13, 2015
ecc91e5
TST: workaround for unpredictable order in list printing
jankatins Aug 13, 2015
b09370e
WIP: review work
tacaswell Aug 20, 2015
0f781a1
TST: test the plot arg replacer directly
jankatins Aug 26, 2015
77be376
FIX: add proper replace_names for some plotting methods
jankatins Aug 26, 2015
7a39ef6
TST: add testcases for some decorated plot methods
jankatins Aug 26, 2015
a0c738e
MNT: regenerate pyplot to get the data kwarg
jankatins Aug 26, 2015
7a6d44d
MNT: make boilerplate.py a bit smarter
tacaswell Aug 27, 2015
bb4b9f7
MNT: add python 3 version of sig parsing
tacaswell Aug 27, 2015
9c1199b
ENH: add 'data' to signature in python 3.3 +
tacaswell Aug 27, 2015
47ff38a
MNT: python 2.6 compatibility fix
tacaswell Aug 27, 2015
00929b9
MNT: yet more compatibility fixes
tacaswell Aug 28, 2015
b6cb12f
ENH: add 'data' kwarg to pyplot
tacaswell Aug 28, 2015
25b1d43
TST: test pyplot.pie with a data kwarg
jankatins Aug 28, 2015
b4f011c
ENH: remove arbitrary long args if used with data
jankatins Aug 28, 2015
61eb622
FIX: small (non-code) fixups
jankatins Aug 31, 2015
e838a25
MNT: put test helper functions into their proper place
jankatins Aug 31, 2015
55ed86e
TST: Test with pandas installed on 2.7
jankatins Aug 31, 2015
9846b9c
DOC: Add a whatsnew entry for labeled data improvements
jankatins Aug 31, 2015
2b2092d
MNT: use IPython's signature if needed + available
tacaswell Sep 8, 2015
572c1e2
Merge pull request #4 from tacaswell/unpack_labeled_data_alternative
jankatins Sep 8, 2015
e2cf264
MNT: use already imported version variables
tacaswell Sep 9, 2015
67fda44
PRF: only try to use IPython if already imported
tacaswell Sep 9, 2015
59f3917
Merge pull request #5 from tacaswell/unpack_labeled_data_alternative
jankatins Sep 10, 2015
1c9feb8
FIX: guard signature import better
tacaswell Sep 11, 2015
1d00767
MNT: use built-in logic for unwrapping
tacaswell Sep 11, 2015
c454983
MNT: rename get_index_y -> index_of
tacaswell Sep 11, 2015
0d6cd40
MNT: enable unpacking on 2D inputs
tacaswell Sep 11, 2015
0734b86
MNT: invert logic of _has_varargs
tacaswell Sep 11, 2015
5fbe4b0
Merge pull request #6 from tacaswell/unpack_labeled_data_alternative
jankatins Sep 11, 2015
f34aed0
MNT: simplify identifying valid style codes
tacaswell Sep 12, 2015
a051b57
MNT: rearrange testing helper functions
tacaswell Sep 12, 2015
8271952
MNT: expose hist(..., weight='key') to data kwarg
tacaswell Sep 12, 2015
0b4fc7c
DOC: edits to whats_new entry
tacaswell Sep 12, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
ENH: Make implicit x in plot pandas aware
Try to grab `y.index` before returning `np.arange(len(y))`
  • Loading branch information
tacaswell authored and jankatins committed Aug 31, 2015
commit 367b68fbb7added330160e426830116cd247212a
7 changes: 3 additions & 4 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import matplotlib.image as mimage
from matplotlib.offsetbox import OffsetBox
from matplotlib.artist import allow_rasterization
from matplotlib.cbook import iterable
from matplotlib.cbook import iterable, get_index_y
from matplotlib.rcsetup import cycler

rcParams = matplotlib.rcParams
Expand Down Expand Up @@ -349,12 +349,11 @@ def _plot_args(self, tup, kwargs):
if v is not None:
kw[k] = v

y = np.atleast_1d(tup[-1])

if len(tup) == 2:
x = np.atleast_1d(tup[0])
y = np.atleast_1d(tup[-1])
else:
x = np.arange(y.shape[0], dtype=float)
x, y = get_index_y(tup[-1])

x, y = self._xy_from_xy(x, y)

Expand Down
28 changes: 28 additions & 0 deletions lib/matplotlib/cbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -2487,6 +2487,34 @@ def pts_to_midstep(x, *args):
'step-post': pts_to_poststep,
'step-mid': pts_to_midstep}


def get_index_y(y):
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps this could be just named index_of?

Copy link
Member

Choose a reason for hiding this comment

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

I don't think either names suit this function, both imply it returns just the index, rather than the indices and the original values...

Which prompts the question, what does this function do that enumerate does not?

Copy link
Member

Choose a reason for hiding this comment

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

@OceanWolf It does 'the right thing' with pd.Series. This is also a place holder where we can put more brains to deal with other types of labeled data that knows what it's index is (and is not accessible via obj.index). Eventually we should probably make this pluggable (like the units framework).

Copy link
Member

Choose a reason for hiding this comment

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

I have a commit to change this to index_of which I agree is better, but still not perfect. It returns both the index and the values (the original name was going for 'get (index, y)' so something that sounds like it should return both would be better (with_index sounds like it should be a context manager, indexed is too ambiguous).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

get_y_for_x? If there is no index, it also adds a range, so...

Copy link
Member

Choose a reason for hiding this comment

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

@JanSchulz if you squint enough range is the 'index' for a unlabeled array.

"""
A helper function to get the index of an input to plot
against if x values are not explicitly given.

Tries to get `y.index` (works if this is a pd.Series), if that
fails, return np.arange(y.shape[0]).

This will be extended in the future to deal with more types of
labeled data.

Parameters
----------
y : scalar or array-like
The proposed y-value

Returns
-------
x, y : ndarray
The x and y values to plot.
"""
try:
return y.index.values, y.values
except AttributeError:
y = np.atleast_1d(y)
return np.arange(y.shape[0], dtype=float), y

# Numpy > 1.6.x deprecates putmask in favor of the new copyto.
# So long as we support versions 1.6.x and less, we need the
# following local version of putmask. We choose to make a
Expand Down