Skip to content

(WIP)ENH: plot now supports cycler #12547

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

Closed
wants to merge 1 commit into from

Conversation

sinhrks
Copy link
Member

@sinhrks sinhrks commented Mar 6, 2016

  • closes Allow to set hatches in 'area' plots #12354
  • tests added / passed
  • passes git diff upstream/master | flake8 --diff
  • whatsnew entry
    • plotting no try to use cycler regardless of mpl version (previously tried if mpl >= 1.5)
    • bug in area plot kwds handling

Cyclic option handling

Allows to accept some option (currently only hatch) as a list, each element is applied to corresponding columns.

This can be more generalized, but I think it's better to refactor plotting submodule beforehand.

Hatch example

df = pd.DataFrame({'A': np.random.randint(0, 10, 10), 
                   'B': np.random.randint(0, 10, 10)})
# we cannot see hatch if alpha=1.0
df.plot.area(hatch='*', alpha=0.5);

index

from cycler import cycler
df.plot.area(hatch=cycler('hatch', ['*', '//']), alpha=0.5);

indexx

@sinhrks sinhrks added the Visualization plotting label Mar 6, 2016
@sinhrks sinhrks added this to the 0.18.1 milestone Mar 6, 2016
@tacaswell
Copy link
Contributor

This is the sort of application that Cycler was written to address. See http://matplotlib.org/examples/api/filled_step.html

@jreback
Copy link
Contributor

jreback commented Mar 13, 2016

yes we can implicity depend on cycler (at least in newer version so mpl, IIRC >= 1.5``.

@tacaswell
Copy link
Contributor

cycler is packaged separately (basically everywhere) so you can directly depend on it without requiring newer mpl.

@jreback
Copy link
Contributor

jreback commented Mar 13, 2016

hmm, ok, then we should probably do that (and add alongside the mpl dep in install).

@jreback jreback modified the milestones: 0.18.2, 0.18.1 Apr 17, 2016
@jreback
Copy link
Contributor

jreback commented May 7, 2016

@sinhrks can we change to use cycler? (and raise if not installed and a list provided)

@jreback
Copy link
Contributor

jreback commented Jun 30, 2016

@sinhrks status?

@jreback jreback removed this from the 0.18.2 milestone Jun 30, 2016
@sinhrks
Copy link
Member Author

sinhrks commented Jul 4, 2016

@jreback Sorry, will revisit to use cycler.

@sinhrks
Copy link
Member Author

sinhrks commented Jul 5, 2016

Updated to use cycler, and would like to decide following points.

1. Whether to add cycler kwds

Because one cycler instance can handle multiple keywords, passing single cycler is enough to handle all options cyclically. Thus, I think adding cycler kwd is simpler (it should overwrite other kwds if specified).

df.plot.area(cycler=cycler('hatch', ['*', '//']), alpha=0.5);

c = cycler('hatch', ['*', '//']) + cycler('ls', ['-', '--'])
df.plot.area(cycler=c, alpha=0.5);

Or, allow to accept cycler instances via every kwds (maybe we have to concatenate all cycler internally before plotting )

df.plot.area(hatch=cycler('hatch', ['*', '//']), alpha=0.5);
df.plot.area(hatch=cycler('hatch', ['*', '//']), ls=cycler('ls', ['-', '--']), alpha=0.5);

# there can be a mismatch between method and cycler kwds
df.plot.area(hatch=cycler('ls', ['-', '--']), alpha=0.5);

2. How to handle cycler which doesn't have required length

cycler itself doesn't repeat its content, I think raising error is natural. User must pass cycler which is longer than required length (number of columns, etc).

Another option is implicitly repeat.

CC: @TomAugspurger

@sinhrks sinhrks changed the title (WIP)ENH: plot now supports cyclic hatch (WIP)ENH: plot now supports cycler Jul 5, 2016
@jorisvandenbossche
Copy link
Member

  • We already have the style keyword. Could we use that to pass a cycler object instead of adding a new cycler keyword argument?
    1. Having a dedicated keyword to pass cycler objects, as well as accepting those for the individual styling keywords (hatch, ls, ..) can in principle both be implemented?
      But if we choose, I would personally start by accepting it for a specific keyword.
    1. raising an error when the cycler is not long enough sounds good to me
  • Giving users the availability of passing a cycler object, should that prevent them also being able to just pass a list?
    Because from a user point, if you have two columns and you want different hatch for each, doing df.plot.area(hatch=cycler('hatch', ['*', '//'])) instead of df.plot.area(hatch=['*', '//']) is quite a bit more complex.

@tacaswell
Copy link
Contributor

I would suggest 1) and converting any lists that come in via kwargs to cyclers that are added together (and to the thing passed into the cycler kwarg) and any length 1 things are converted to length 1 cyclers that are multiplied.

That would give you one cycler to worry about internally, not put too much burden on your user and give them access to the full power of cycler if they want it.

@tacaswell
Copy link
Contributor

tacaswell commented Jul 6, 2016

And if you 'call' a cycler

for c in cyc():
   ...

vs

for c in cycr:
    ...

It will implicitly repeat.

@sinhrks
Copy link
Member Author

sinhrks commented Jul 6, 2016

Thanks, how about following spec?

  • Cycler can be used via following kwds:
    • style: can accept Cycler with whatever keys
      • if specified Cycler key conflicts with other keywords, raises error.
    • other mpl kwds: can accept Cycler with corresponding single key (e.g. ls kw can accept Cycler(ls=...), but can't Cycler(lw=...), etc)
      • if user passes list, it will be automatically converted to Cycler (as long as mpl/pandas plotting can't accept list via the kw). If Cycler is not installed, raise understandable error to show Cycler is required.
  • Cycler (or passed list) implicitly loops (looks need Cycler >= 0.10)
  • (Needs discussion) Show warning if Cycler is not installed. To replace color-cycle logic in future.

@sinhrks sinhrks added this to the 0.19.0 milestone Jul 6, 2016
@tacaswell
Copy link
Contributor

Also if cycler has any sharp edges, we can probably fix it upstream.

@jorisvandenbossche
Copy link
Member

@sinhrks status of this? (I think the spec you outlined above looks fine!)

Can you also add a whatsnew notice? And probably something in the install instructions. cycler is regarded as an optional dependency for plotting? (passing style kwargs does still work if you don't not have cycler installed?)

@jreback jreback removed this from the 0.19.0 milestone Aug 26, 2016
@jreback
Copy link
Contributor

jreback commented Nov 16, 2016

@sinhrks can you update

@jreback
Copy link
Contributor

jreback commented Feb 1, 2017

@sinhrks status?

@jreback
Copy link
Contributor

jreback commented May 6, 2017

closing, but if you can update @sinhrks pls reopen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow to set hatches in 'area' plots
4 participants