Skip to content

Temporary styling ignores color cycle #11376

Closed

Description

@rjurga

Bug report

Bug summary

With temporary styling, using colors with respect to the color cycle, like 'C0', is ignored if plt.show() is called outside of the with block. It only works properly if plt.show() is called inside the block.

Code for reproduction

This reproduces the bug:

import matplotlib.pyplot as plt

with plt.style.context('seaborn'):
    plt.axhline(0, color='C0')
    plt.axhline(1, color='C1')
    plt.axhline(2, color='C2')
plt.show()

This works fine and is the expected behavior:

import matplotlib.pyplot as plt

with plt.style.context('seaborn'):
    plt.axhline(0, color='C0')
    plt.axhline(1, color='C1')
    plt.axhline(2, color='C2')
    plt.show()

Actual outcome

does_not_work

Please note that other elements of the style are working fine, such as the grid.

Expected outcome

works

Matplotlib version

  • Operating system: Solus Linux
  • Matplotlib version: 2.2.2
  • Matplotlib backend (print(matplotlib.get_backend())): TkAgg
  • Python version: 3.6.5

Using matplotlib packaged by the linux distribution.

Activity

  1. afvincent commented on Jun 5, 2018

    @afvincent
    Contributor

    @rjurga Thank you for the report :)!

    I can reproduce this on master (with Fedora 28 and Python 3.6 from conda).

  2. added this to the v3.0 milestone on Jun 5, 2018
  3. WeatherGod commented on Jun 6, 2018

    @WeatherGod
    Member
  4. tacaswell commented on Jun 6, 2018

    @tacaswell
    Member

    It does look like the color is resloved at draw time, however for other things that hit the rcparams we resolve them at call time to exactly avoid issues like this.

    We should probably move the resolution of the 'C#' values up sooner (have it be done in Line2D.set_color) and document the API change unless we can dig up documentation of why we did it this way.

  5. WeatherGod commented on Jun 6, 2018

    @WeatherGod
    Member
  6. added
    API: consistencyConsistency of the matplotlib API, including naming, behavior, defaults, …
    on Jun 21, 2018
  7. jklymak commented on Jun 21, 2018

    @jklymak
    Member

    I dunno - I think if you drop out of context, you can/should expect strange things to do with the context to happen. i.e. in the code above, I'd plt.show or fig.savefig inside the context. Is this really a bug?

  8. WeatherGod commented on Jun 21, 2018

    @WeatherGod
    Member
  9. modified the milestones: v3.0, v3.1 on Jul 9, 2018
  10. jklymak commented on Feb 9, 2019

    @jklymak
    Member

    I'm closing this as won't fix....

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions