8000 backend partially ignores "figure.figsize" in plt.rc_context in jupyter · Issue #23513 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content
backend partially ignores "figure.figsize" in plt.rc_context in jupyter #23513
Closed
@juhuebner

Description

@juhuebner

Bug summary

This possibly related to #20738

When I run the code below on a new jupyter kernel, only the tick styling is working. The figure.size and figure.dpi is ignored first.

One has to run something interacting with the backend first (like matplotlib.pyplot.show() ) in order to get plt.rc_context() working correctly.

Is this normal behavior, since the correct backend already seems to be activated or did I oversee something?

Code for reproduction

import matplotlib.pyplot as plt

rc = {"figure.figsize": [6, 1], "figure.dpi": 150, "xtick.direction": "in", "ytick.direction": "in"}

# Uncommenting this helps, but is this the intended behavoiur in jupyter?
# plt.show()

with plt.rc_context(rc):
    # Sanity check.
    print(f"{plt.rcParams['figure.figsize']=}")
    print(f"{plt.rcParams['figure.dpi']=}")
    print(f"{plt.rcParams['backend']=}")
    fig, ax = plt.subplots()

    # ax.plot(x, x)
    plt.show()

Actual outcome

plt.rcParams['figure.figsize']=[6.0, 1.0]
plt.rcParams['figure.dpi']=150.0
plt.rcParams['backend']='module://matplotlib_inline.backend_inline'

image

Expected outcome

Runnig the code twice, which has then plt.show() already called once delivers the correct output:
download

Additional information

No response

Operating system

No response

Matplotlib Version

3.5.2

Matplotlib Backend

module://matplotlib_inline.backend_inline

Python version

Python 3.9.7

Jupyter version

6.4.12

Installation

No response

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

      0