<h3 dir="auto">Bug summary</h3>
<p dir="auto">When you load a stylesheet with a figure.dpi setting, then the dpi setting is not honored in the first figure. (It is honored in subsequent figures).</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="import numpy as np
import matplotlib as mpl
import matplotlib.pyplot as plt
from pathlib import Path
cfgdir = mpl.get_configdir()

# --- First create a custom style file with just a dpi setting ---
p = Path(cfgdir)
stylelib = (p / 'stylelib')
stylelib.mkdir(exist_ok=True)
path = stylelib / 'mplbug.mplstyle'
path.write_text(&quot;figure.dpi: 200&quot;)

plt.style.reload_library()

x = np.cos(np.linspace(0,4*np.pi,200))
plt.style.use('mplbug')
plt.plot(x)"><pre class="notranslate"><span class="pl-k">import</span> <span class="pl-s1">numpy</span> <span class="pl-k">as</span> <span class="pl-s1">np</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">as</span> <span class="pl-s1">mpl</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>
<span class="pl-k">from</span> <span class="pl-s1">pathlib</span> <span class="pl-k">import</span> <span class="pl-v">Path</span>
<span class="pl-s1">cfgdir</span> <span class="pl-c1">=</span> <span class="pl-s1">mpl</span>.<span class="pl-en">get_configdir</span>()

<span class="pl-c"># --- First create a custom style file with just a dpi setting ---</span>
<span class="pl-s1">p</span> <span class="pl-c1">=</span> <span class="pl-v">Path</span>(<span class="pl-s1">cfgdir</span>)
<span class="pl-s1">stylelib</span> <span class="pl-c1">=</span> (<span class="pl-s1">p</span> <span class="pl-c1">/</span> <span class="pl-s">'stylelib'</span>)
<span class="pl-s1">stylelib</span>.<span class="pl-en">mkdir</span>(<span class="pl-s1">exist_ok</span><span class="pl-c1">=</span><span class="pl-c1">True</span>)
<span class="pl-s1">path</span> <span class="pl-c1">=</span> <span class="pl-s1">stylelib</span> <span class="pl-c1">/</span> <span class="pl-s">'mplbug.mplstyle'</span>
<span class="pl-s1">path</span>.<span class="pl-en">write_text</span>(<span class="pl-s">"figure.dpi: 200"</span>)

<span class="pl-s1">plt</span>.<span class="pl-s1">style</span>.<span class="pl-en">reload_library</span>()

<span class="pl-s1">x</span> <span class="pl-c1">=</span> <span class="pl-s1">np</span>.<span class="pl-en">cos</span>(<span class="pl-s1">np</span>.<span class="pl-en">linspace</span>(<span class="pl-c1">0</span>,<span class="pl-c1">4</span><span class="pl-c1">*</span><span class="pl-s1">np</span>.<span class="pl-s1">pi</span>,<span class="pl-c1">200</span>))
<span class="pl-s1">plt</span>.<span class="pl-s1">style</span>.<span class="pl-en">use</span>(<span class="pl-s">'mplbug'</span>)
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>(<span class="pl-s1">x</span>)</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">when i run this exact code two times in a row in a jupyter notebook, then the figure size is not the same the two times.  It is wrong in the first figure.</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">I expect the figure to be big the first time and all subsequent times.</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto"><em>No response</em></p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Windows</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.2</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">module://ipykernel.pylab.backend_inline</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">3.8.5</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto">6.1.4</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">conda</p>
<h3 dir="auto">Bug summary</h3>
<p dir="auto">First invocation of <code class="notranslate">plt.plot()</code> resets <code class="notranslate">mpl.rcParams['figure.dpi']</code>.</p>
<h3 dir="auto">Code for reproduction</h3>
<div class="highlight highlight-source-python notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="# Only tested in Jupyter

import matplotlib as mpl
import matplotlib.pyplot as plt

mpl.rcParams['figure.dpi'] = 300

print(mpl.rcParams['figure.dpi'])
plt.plot()
print(mpl.rcParams['figure.dpi'])"><pre class="notranslate"><span class="pl-c"># Only tested in Jupyter</span>

<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span> <span class="pl-k">as</span> <span class="pl-s1">mpl</span>
<span class="pl-k">import</span> <span class="pl-s1">matplotlib</span>.<span class="pl-s1">pyplot</span> <span class="pl-k">as</span> <span class="pl-s1">plt</span>

<span class="pl-s1">mpl</span>.<span class="pl-s1">rcParams</span>[<span class="pl-s">'figure.dpi'</span>] <span class="pl-c1">=</span> <span class="pl-c1">300</span>

<span class="pl-en">print</span>(<span class="pl-s1">mpl</span>.<span class="pl-s1">rcParams</span>[<span class="pl-s">'figure.dpi'</span>])
<span class="pl-s1">plt</span>.<span class="pl-en">plot</span>()
<span class="pl-en">print</span>(<span class="pl-s1">mpl</span>.<span class="pl-s1">rcParams</span>[<span class="pl-s">'figure.dpi'</span>])</pre></div>
<h3 dir="auto">Actual outcome</h3>
<p dir="auto">300.0<br>
72.0</p>
<h3 dir="auto">Expected outcome</h3>
<p dir="auto">300.0<br>
300.0</p>
<h3 dir="auto">Additional information</h3>
<p dir="auto">This happens only at the very first invocation of <code class="notranslate">plt.plot()</code>, while on subsequent <code class="notranslate">plt.plot()</code> calls <code class="notranslate">mpl.rcParams['figure.dpi']</code> will no longer be overwritten.</p>
<p dir="auto">Other <code class="notranslate">rcParams</code> values seem not to be affected (but I've not tested them all).</p>
<p dir="auto">I have never observed this behavior in any of the previous matplotlib versions, so the bug must have been introduced in the latest version (3.5.2).</p>
<h3 dir="auto">Operating system</h3>
<p dir="auto">Windows 10</p>
<h3 dir="auto">Matplotlib Version</h3>
<p dir="auto">3.5.2</p>
<h3 dir="auto">Matplotlib Backend</h3>
<p dir="auto">module://matplotlib_inline.backend_inline</p>
<h3 dir="auto">Python version</h3>
<p dir="auto">Python 3.9.12</p>
<h3 dir="auto">Jupyter version</h3>
<p dir="auto">3.4.0</p>
<h3 dir="auto">Installation</h3>
<p dir="auto">conda</p>