Skip to content

[Bug]: Inconsistent behavior of stylesheet contexts in Jupyter Notebooks #30170

Open
@janikkokot

Description

@janikkokot

Bug summary

Using style sheets with the plt.style.context context manager only updates some style changes in Jupyter Notebooks/Quarto documents.

Code for reproduction

import matplotlib.pyplot as plt
from cycler import cycler
def example_plot(line_style, scatter_style):
    fig, ax = plt.subplots()
    ax.plot([0, 1], [0, 1], **line_style)
    ax.scatter([0, 0, 1, 1], [0, 1, 0, 1], **scatter_style)


line_style = dict(color='C1')
scatter_style = dict(color='C0', ec='C1')

rc_style = {'axes.prop_cycle': cycler(color=['#fff', '#000'])}
plt.style.use('default')
example_plot(line_style, scatter_style)
with plt.style.context(rc_style, after_reset=True):
    example_plot(line_style, scatter_style)
plt.style.use(rc_style)
example_plot(line_style, scatter_style)
plt.style.use('default')
example_plot(line_style, scatter_style)

with plt.style.context(rc_style):
    example_plot(line_style, scatter_style)

plt.style.use(rc_style)
example_plot(line_style, scatter_style)

Actual outcome

In separate code cells

default style with use

Image

custom style with context

Image

custom style with use

Image

in one code cell

default style with use

Image

custom style with context

Image

custom style with use

Image

Expected outcome

default style with use

Image

custom style with context

Image

custom style with use

Image

Additional information

Quarto version: 1.7.31

Operating system

Ubuntu

Matplotlib Version

3.10.3

Matplotlib Backend

'module://matplotlib_inline.backend_inline'

Python version

Python 3.12.10

Jupyter version

7.4.3

Installation

pip

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions