Skip to content
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

Adds metadata to help display matplotlib figures legibly #336

Merged

Conversation

telamonian
Copy link
Contributor

@telamonian telamonian commented Aug 28, 2018

This is the sister PR of jupyterlab/jupyterlab#5232.

This PR adds some code so that when the matplotlib inline backend is enabled, one piece of extra metadata ('needs-background') is passed along with each figure. This allows frontends to intelligently display a background behind the figure if it's needed to make the tick labels on the figure legible. This is implemented as so:

Whenever the inline backend calls the display(fig, metadata) function, fig is first checked to see if it has a transparent background. If it does, the color of each tick label in the figure is checked to see if it's light or dark. If all of the ticks are light, then 'needs-background': 'light' is added to metadata, or if all are dark then 'needs-background': 'dark' is added. Otherwise, nothing is added to metadata.

See jupyterlab/jupyterlab#5232 for an example of an implementation of a frontend legibility fix using 'needs-background'.

@blink1073
Copy link
Member

Nice, thanks @telamonian! @minrk, it looks like tornado requires 3.4+ now, which is causing the CI failure. Any objections to switching this library to 3.4+ as well?

@blink1073
Copy link
Member

@minrk
Copy link
Member

minrk commented Aug 29, 2018

@blink1073 nope, go for it. Just make sure to update python_requires in setup.py

@blink1073
Copy link
Member

Pushed the changes for 3.4+

@blink1073
Copy link
Member

Oh wait, I was thinking that we were keeping python 2.7 support, should we drop that as well?

@minrk
Copy link
Member

minrk commented Aug 29, 2018

Let's not drop 2.7 just yet. So that would be the ever-so-convenient:

python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*',

@blink1073
Copy link
Member

Ha! Clear as mud

@blink1073 blink1073 added this to the 4.9 milestone Aug 29, 2018
@blink1073
Copy link
Member

In she goes!

@blink1073 blink1073 merged commit 3a24c2b into ipython:master Aug 29, 2018
@ccordoba12
Copy link
Member

Thanks @telamonian for working on this one!! This is great!

We'll use it in Spyder too.

@blink1073
Copy link
Member

Sweet!

@ian-r-rose
Copy link
Contributor

Very exciting to see this land, and glad it will get some use in multiple clients!

@Carreau
Copy link
Member

Carreau commented Aug 29, 2018

That's great ! Definitively a huge plus for having organized sprint and community day.

cc @rgbkrk for nteract support, and informing @tacaswell.

for label in axis.get_ticklabels()])
if ticksLight.size and (ticksLight == ticksLight[0]).all():
# there are one or more tick labels, all with the same lightness
return {'needs_background': 'dark' if ticksLight[0] else 'light'}
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

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.

None yet

7 participants