Closed
Description
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'
Expected outcome
Runnig the code twice, which has then plt.show()
already called once delivers the correct output:
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
Labels
No labels