Skip to content

[MRG] use mpl default color cycle - #5186

Merged
larsoner merged 16 commits into
mne-tools:masterfrom
sappelhoff:use_mpl_default_colors
Aug 12, 2018
Merged

larsoner merged 16 commits into
mne-tools:masterfrom
sappelhoff:use_mpl_default_colors

Conversation

@sappelhoff

Copy link
Copy Markdown
Member

fixes #5154

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

Hm ... the default color cycle is horrid for MPL < 2.0 (or 1.5, I forgot). Maybe we can detect the MPL version, and set it to the MPL color cycle if it's recent, and set it to the corresponding HTML colors if it's not (and when the old versions of MPL are no longer supported, the latter code is dropped)?

Or is that too involved for what used to be a simple list of hex vals?

@agramfort

Copy link
Copy Markdown
Member

@sappelhoff can you show how examples look like now?

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

Maybe we can detect the MPL version, and set it to the MPL color cycle if it's recent, and set it to the corresponding HTML colors if it's not (and when the old versions of MPL are no longer supported, the latter code is dropped)?

I would rather just copy the HTML codes directly and use them always. mpl doesn't change their color cycle that often, and it simplifies the code at our end.

@sappelhoff

Copy link
Copy Markdown
Member Author

given the current errors, I think copying in the new mpl default hex codes is the way to go ...

regarding showing how the examples look like ... I did the following:

  1. in my fork, go to the branch
  2. within the branch go to /doc
  3. run make html_dev

... unfortunately, that has been running for 30 minutes now and seems to be stuck at:

generating gallery for auto_examples/datasets... [ 40%] plot_megsim_data_single_Decompressing 101 files from
"subject1_singleTrials_VisWorkingMem_fif.zip" ... [done]

I thought this would build the docs new (locally) with my changed code, so that I could then simply view the resulting files in my browser and make a screenshot.

Am I doing this the wrong way?

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

There is a line you can add to your commit message that will mean you get the entire CircleCI rebuild. I can't find it though - @larsoner ?

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

[circle full] in the commit message will do a full build. It takes about 2 hours, maybe 1-1.5 locally.

If you want to do specific examples locally use PATTERN=plot_whatever.py make html_dev-pattern. PATTERN is a regular expression so you can add multiple ones if you want, too.

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

As I mentioned in the related issue, you need to do something special to replace 'r' with whatever the red-most color is in the viz code, see failures:

https://travis-ci.org/mne-tools/mne-python/jobs/374871620

@sappelhoff

sappelhoff commented May 4, 2018 •

Copy link
Copy Markdown
Member Author

I tried to find some handy tool that picks the most "red" color out of a list of hex codes ... but I didn't find something nice and short ... so I just picked by hand and started replacing the 'r' code with that hexcode.

What about these lines

... is this referring to white and blue? If so, the blue should perhaps be replaced as well with the MPL hexcolor.

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

No those are actual keypress codes not colors :)

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

so I just picked by hand and started replacing the 'r' code with that hexcode.

This could go in the same place as the CYCLE and be named e.g. BAD_COLOR. Then if we change it in the future we change it in one place

@codecov

codecov Bot commented May 4, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #5186 into master will decrease coverage by 0.01%.
The diff coverage is 84.21%.

@@            Coverage Diff             @@
##           master    #5186      +/-   ##
==========================================
- Coverage   88.28%   88.27%   -0.02%     
==========================================
  Files         358      358              
  Lines       66221    66298      +77     
  Branches    11251    11253       +2     
==========================================
+ Hits        58461    58522      +61     
- Misses       4951     4965      +14     
- Partials     2809     2811       +2

@sappelhoff

Copy link
Copy Markdown
Member Author

Something like:

BAD_COLOR = u'#d62728'
COLORS = [u'#1f77b4', u'#ff7f0e', u'#2ca02c', BAD_COLOR, u'#9467bd',
          u'#8c564b', u'#e377c2', u'#7f7f7f', u'#bcbd22', u'#17becf']

and then replace those conditional 'r' lines to BAD_COLOR?

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

Yeah that's what I had in mind, let's see if the CIs agree

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

@sappelhoff can you take a few minutes to try this and see if it works as it does on master:

import mne
raw = mne.io.read_raw_fif(mne.datasets.sample.data_path() +
                          "/MEG/sample/sample_audvis_filt-0-40_raw.fif")
raw.annotations = mne.Annotations([1], [1], 'BAD_DRAG')
fig = raw.plot()
fig.canvas.key_press_event('a')  # annotation mode

Also paste a screenshot of how it looks now that the color has changed?

@sappelhoff

sappelhoff commented May 4, 2018 •

Copy link
Copy Markdown
Member Author

Seems to work ...

screenshot from 2018-05-04 17-47-48

Except for:

/home/stefanappelhoff/miniconda3/envs/mne/lib/python2.7/site-packages/matplotlib/collections.py:360: UserWarning: Collection picker None could not be converted to float
  % self._picker)

@larsoner

larsoner commented May 4, 2018

Copy link
Copy Markdown
Member

Looks red enough to me

@sappelhoff

Copy link
Copy Markdown
Member Author

Okay, and the CIs are happy. How do we make use of the [circle full] now? Wasn't that so we could see how the examples look like with the new colors?

@sappelhoff

Copy link
Copy Markdown
Member Author

Thanks @larsoner, but then I'd probably have to set up circle CI for my fork, right? I think that's too much trouble for now.

To me, the colors look fine, neither exciting nor ugly.

@larsoner

larsoner commented May 6, 2018 via email

Copy link
Copy Markdown
Member

Comment thread mne/viz/utils.py Outdated
'#CD7F32', '#FF4040', '#ADFF2F', '#8E2323', '#FF1493']
BAD_COLOR = u'#d62728'
COLORS = [u'#1f77b4', u'#ff7f0e', u'#2ca02c', BAD_COLOR, u'#9467bd',
u'#8c564b', u'#e377c2', u'#7f7f7f', u'#bcbd22', u'#17becf']

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would not do it like this. If we now use mpl defaults we should use its rcParams. If someone want to change the MNE colors it would be able to do it via setting the global mpl default values.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

but how would you identify a "bad color" out of the rcParams? Especially, if these colors could change anytime via the global mpl default vals?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

  1. Use whatever is in rcParams at the time of plotting (so we'll need a private _get_color_cycle function or so that we call whenever we start a plotting function that wants a color cycle)
  2. For annotations (this logic can also be in _get_color_cycle(..., annotations=False)):
    1. If 'r' is in the list, use it as bad color when plotting annotations
    2. If not, add it and use it

@jona-sassenhagen

jona-sassenhagen commented May 6, 2018 •

Copy link
Copy Markdown
Contributor

We're gonna drive @sappelhoff crazy :)

@agramfort

agramfort commented May 6, 2018 via email

Copy link
Copy Markdown
Member

@larsoner

larsoner commented May 6, 2018

Copy link
Copy Markdown
Member

And plot_dipole_amplitudes can call the same function with annotations=False to get the color cycle.

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

'C3' looks rather red:

unknown-147

I don't know the function, but could the line in question be marked with a linestyle too?

The "look for 'r'" thing sounds fishy to me ...

@larsoner

larsoner commented May 6, 2018 via email

Copy link
Copy Markdown
Member

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

What I mean is, if both C3 and r show up on the same plot, they will be easily confused.

@larsoner

larsoner commented May 6, 2018 via email

Copy link
Copy Markdown
Member

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

@sappelhoff wanna finish this?

@larsoner

larsoner commented Aug 9, 2018

Copy link
Copy Markdown
Member

(BTW also please use [circle full] as sparingly as possible as the 2h it takes to render all docs vs a couple isolated examples hurts us in terms of staying within our usage limits.)

Comment thread mne/viz/utils.py Outdated
fname_out : str
The filename used for storing the diff. Could be useful for
when a temporary file is used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why all of these?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

to comply with pydocstyle pep257 ... it's cosmetic and should be avoided, I know ... I tried to limit it

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't see it in that spec. One of their example even does not have it:

def complex(real=0.0, imag=0.0):
    """Form a complex number.

    Keyword arguments:
    real -- the real part (default 0.0)
    imag -- the imaginary part (default 0.0)
    """
    if imag == 0.0 and real == 0.0:
        return complex_zero
    ...

Does make docstyle complain for you? It's what we use for checking docstyle

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

yes, it does not seem to be in the spec. I used pydocstyle. Apparently pep257 doesn't say anything about this ...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes we use pydocstyle in our CIs but we have specific includes/excludes that we follow. Doing make docstyle in the mne-python root does the tests that we follow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

wouldn't it be better to accept only "one style", either with a blank line before the end of the docstring or without it? Right now it's very mixed across the codebase.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes at some point. Right now I think we have predominantly followed having no newline.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So revert these too

@sappelhoff

Copy link
Copy Markdown
Member Author

@agramfort

Copy link
Copy Markdown
Member

@sappelhoff travis is not happy

is this MRG?

can you point to the rendered examples affected by this?

@sappelhoff

Copy link
Copy Markdown
Member Author

@sappelhoff travis is not happy

true, but I don't really know what to do with this error:

No output has been received in the last 10m0s, this potentially indicates a stalled build or something wrong with the build itself. Check the details on how to adjust your build configuration on: https://docs.travis-ci.com/user/common-build-problems/#Build-times-out-because-no-output-was-received The build has been terminated

it seems unrelated

can you point to the rendered examples affected by this?

See: https://8929-1301584-gh.circle-artifacts.com/0/html/auto_examples/inverse/plot_custom_inverse_solver.html

I didn't build the other examples to use CircleCI sparingly, as sensibly advised by @larsoner

@agramfort

Copy link
Copy Markdown
Member

@sappelhoff I restarted the travis failure.

one trick is to make a cosmit in the affected examples so they get rendered by circle

@sappelhoff

sappelhoff commented Aug 10, 2018 •

Copy link
Copy Markdown
Member Author

one trick is to make a cosmit in the affected examples so they get rendered by circle

@agramfort: yes, I selected the example where the changes of this PR would be most apparent, and then made some cosmetic changes there. That's the example I linked to above. Travis is happy again :-)

Comment thread mne/viz/evoked.py
if color is None:
if dark_background:
color = ['w'] + COLORS
color = ['w'] + _get_color_list()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

did you check the plot_evoked_topo with dark_background ?

@sappelhoff

Copy link
Copy Markdown
Member Author

@agramfort see below for several screenshots of mne.viz.plot_evoked_topo using the new colors

Dark background ('k') legend

image

Dark background, zoomed in

image

Light background ('w') legend

image

Light background, zoomed in

image

@sappelhoff

Copy link
Copy Markdown
Member Author

mmmh I don't really see why the coverage is reduced ...

apart from that, I think this is ready to be merged.

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than needing to revert the newlines +1 for merge

-------
stc : instance of SourceEstimate
The source estimates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Revert these

Comment thread mne/viz/utils.py Outdated
fname_out : str
The filename used for storing the diff. Could be useful for
when a temporary file is used.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

So revert these too

@sappelhoff sappelhoff changed the title use mpl default color cycle [MRG] use mpl default color cycle Aug 12, 2018

@larsoner larsoner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than two minor things LGTM

Comment thread doc/whats_new.rst Outdated

- Prepare transition to Python 3. This release will be the last release compatible with Python 2. The next version will be Python 3 only.

- func:`mne.viz.plot_evoked_topo` and other functions requiring a color cycle will now default to Matplotlib rcParams colors through :func:`mne.viz.utils._get_color_list`: by `Stefan Appelhoff`_

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

only things in python_reference.rst will link properly with :func:, also we don't usually talk about private functions in whats_new.rst. So instead of having the private functions mentioned it's better to simply omit the "through" part or say something like "... and other functions requiring a color cycle have been refactored to ..." or

Comment thread mne/viz/utils.py Outdated

def __init__(self, ax, collection, ch_names,
alpha_other=0.3): # noqa: D102
alpha_other=0.3): # noqa: D107

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@agramfort

Copy link
Copy Markdown
Member

@larsoner and @jona-sassenhagen ok for you? if so good to go from my end.

thx @sappelhoff

@jona-sassenhagen

Copy link
Copy Markdown
Contributor

I love it!

Circle:

Error while fetching file https://osf.io/86qa2/download. Dataset fetching aborted.
...
socket.timeout: The read operation timed out

@larsoner

Copy link
Copy Markdown
Member

CircleCI has been flakey lately

@larsoner
larsoner merged commit f21b843 into mne-tools:master Aug 12, 2018
@larsoner

Copy link
Copy Markdown
Member

Thanks @sappelhoff

@sappelhoff
sappelhoff deleted the use_mpl_default_colors branch August 12, 2018 20:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Easy] Switch default colors to MPL defaults?

4 participants