rcParams and Style Sheets
rcParams and Style Sheets
Core Principle: Global styling defaults configured through
mpl.rcParamsor reusable style sheets enforce consistent typography, figure sizing, and aesthetic standards across entire computational pipelines.
rcParams
A dict of ~300 defaults controlling every aspect of rendering:
/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/mpl-data/matplotlibrc
Setting pdf.fonttype: 42 and axes.spines.top/right: False here means you never think about them again. See Saving Figures.
Style sheets
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/style/__init__.py", line 130, in use
style = rc_params_from_file(style, use_default_template=False)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/__init__.py", line 968, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error=fail_on_error)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/__init__.py", line 900, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
~~~~~~~~~~~~~~~~~^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/contextlib.py", line 141, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/__init__.py", line 877, in _open_file_or_url
with open(fname, encoding='utf-8') as f:
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'custom.mplstyle'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/leviosman/Developer/python-for-bio/webapp/scripts/curriculum/generate_cell_outputs.py", line 132, in run_cell_capture
exec(compile(code, "<cell>", "exec"), namespace)
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<cell>", line 6, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/style/__init__.py", line 132, in use
raise OSError(
...<2 lines>...
f"styles are listed in `style.available`)") from err
OSError: 'custom.mplstyle' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)
Note the seaborn-v0_8- prefix: matplotlib renamed the bundled seaborn styles when seaborn 0.12 changed. Old code using plt.style.use("seaborn") breaks on modern matplotlib.
A project style file
Create paper.mplstyle:
font.family : sans-serif
font.sans-serif : Arial, Helvetica, DejaVu Sans
font.size : 8
axes.labelsize : 8
axes.titlesize : 9
axes.titlelocation : left
xtick.labelsize : 7
ytick.labelsize : 7
legend.fontsize : 7
legend.frameon : False
axes.spines.top : False
axes.spines.right : False
axes.grid : True
axes.axisbelow : True
grid.alpha : 0.3
grid.linewidth : 0.4
lines.linewidth : 1.2
figure.figsize : 3.5, 2.6
figure.dpi : 110
savefig.dpi : 300
savefig.bbox : tight
pdf.fonttype : 42
ps.fonttype : 42
svg.fonttype : none
axes.prop_cycle : cycler('color', ['4C72B0','DD8452','55A868','C44E52','8172B3','937860'])
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/style/__init__.py", line 130, in use
style = rc_params_from_file(style, use_default_template=False)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/__init__.py", line 968, in rc_params_from_file
config_from_file = _rc_params_in_file(fname, fail_on_error=fail_on_error)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/__init__.py", line 900, in _rc_params_in_file
with _open_file_or_url(fname) as fd:
~~~~~~~~~~~~~~~~~^^^^^^^
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/contextlib.py", line 141, in __enter__
return next(self.gen)
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/__init__.py", line 877, in _open_file_or_url
with open(fname, encoding='utf-8') as f:
~~~~^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [Errno 2] No such file or directory: 'paper.mplstyle'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/Users/leviosman/Developer/python-for-bio/webapp/scripts/curriculum/generate_cell_outputs.py", line 128, in run_cell_capture
value = eval(compile(tail, "<cell>", "eval"), namespace)
File "<cell>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.14/lib/python3.14/site-packages/matplotlib/style/__init__.py", line 132, in use
raise OSError(
...<2 lines>...
f"styles are listed in `style.available`)") from err
OSError: 'paper.mplstyle' is not a valid package style, path of style file, URL of style file, or library style name (library styles are listed in `style.available`)
Commit this file to your repository. It makes every figure in the paper consistent, it documents your choices, and a collaborator regenerating your figures gets the same output. Note that hex colours in a style file have no # prefix: a frequent source of configuration errors.
seaborn's set_theme
Usually easier than raw rcParams, because it sets a coherent group at once:
sns.set_theme(
style="whitegrid", # darkgrid, whitegrid, dark, white, ticks
context="paper", # paper, notebook, talk, poster
palette="colorblind",
font="Arial",
font_scale=1.0,
rc={"figure.figsize": (5, 3.5), "pdf.fonttype": 42},
)
sns.set_theme() modifies matplotlib's rcParams, so it affects your raw matplotlib plots too. One call at the top of a script styles everything.
context scales all font and line sizes together:
| context | For |
|---|---|
paper |
journal figures: smallest |
notebook |
the default |
talk |
slides |
poster |
largest |
Building a figure for a talk is sns.set_theme(context="talk") and re-running, not manually bumping fifteen font sizes.
sns.set_context("talk", font_scale=1.1)
sns.axes_style() # inspect the current style dict
with sns.axes_style("white"): # temporary
...
Fonts
['.ADT Slab Numeric', '.ADT Slab Soft Numeric', '.Al Bayan PUA', '.Al Nile PUA', '.Al Tarikh PUA', '.Apple SD Gothic NeoI', '.Aqua Kana', '.Aqua Kana Bold', '.Arial Hebrew Desk Interface', '.Baghdad PUA', '.Beirut PUA', '.CJK Symbols Fallback HK', '.CJK Symbols Fallback JA', '.CJK Symbols Fallback MO', '.CJK Symbols Fallback SC', '.CJK Symbols Fallback TC', '.CJK Symbols Fallback Watch HK', '.CJK Symbols Fallback Watch JA', '.CJK Symbols Fallback Watch MO', '.CJK Symbols Fallback Watch SC', '.CJK Symbols Fallback Watch TC', '.Damascus PUA', '.DecoType Naskh PUA', '.DecoType Nastaleeq Urdu UI', '.Diwan Kufi PUA', '.Farah PUA', '.Geeza Pro Interface', '.Geeza Pro PUA', '.Hiragino Kaku Gothic Interface', '.Hiragino Sans GB Interface', '.Hiragino Sans GB Interface W3', '.Hiragino Sans GB Interface W6', '.Keyboard', '.KufiStandardGK PUA', '.Lucida Grande UI', '.Muna PUA', '.Nadeem PUA', '.New York', '.New York Numeric', '.New York Soft Numeric', '.Noto Nastaliq Urdu UI', '.SF Adaptive Numeric', '.SF Adaptive Soft Numeric', '.SF Arabic', '.SF Arabic Rounded', '.SF Armenian', '.SF Armenian Rounded', '.SF Bangla', '.SF Camera', '.SF Compact', '.SF Compact Rounded', '.SF Devanagari', '.SF Georgian', '.SF Georgian Rounded', '.SF Gujarati', '.SF Gurmukhi', '.SF Hebrew', '.SF Hebrew Rounded', '.SF Kannada', '.SF Malayalam', '.SF NS Mono', '.SF NS Rounded', '.SF Numeric', '.SF Odia', '.SF Rail Numeric', '.SF Rail Rounded Numeric', '.SF Rounded Numeric', '.SF Soft Numeric', '.SF Stencil Numeric', '.SF Tamil', '.SF Telugu', '.Sana PUA', '.Savoye LET CC.', '.ThonburiUI', '.ThonburiUIWatch', 'Academy Engraved LET', 'Al Bayan', 'Al Nile', 'Al Tarikh', 'American Typewriter', 'Andale Mono', 'Apple Braille', 'Apple Chancery', 'Apple SD Gothic Neo', 'Apple Symbols', 'AppleGothic', 'AppleMyungjo', 'Arial', 'Arial Black', 'Arial Hebrew', 'Arial Hebrew Scholar', 'Arial Narrow', 'Arial Rounded MT Bold', 'Arial Unicode MS', 'Athelas', 'Avenir', 'Avenir Black', 'Avenir Black Oblique', 'Avenir Book', 'Avenir Heavy', 'Avenir Light', 'Avenir Medium', 'Avenir Next', 'Avenir Next Condensed', 'Avenir Next Condensed Demi Bold', 'Avenir Next Condensed Heavy', 'Avenir Next Condensed Medium', 'Avenir Next Condensed Ultra Light', 'Avenir Next Demi Bold', 'Avenir Next Heavy', 'Avenir Next Medium', 'Avenir Next Ultra Light', 'Ayuthaya', 'Baghdad', 'Bangla MN', 'Bangla Sangam MN', 'Baskerville', 'Beirut', 'Big Caslon', 'Bodoni 72', 'Bodoni 72 Oldstyle', 'Bodoni 72 Smallcaps', 'Bodoni Ornaments', 'Bradley Hand', 'Brush Script MT', 'Chalkboard', 'Chalkboard SE', 'Chalkduster', 'Charter', 'Charter Black', 'Cochin', 'Comic Sans MS', 'Copperplate', 'Corsiva Hebrew', 'Courier', 'Courier New', 'DIN Alternate', 'DIN Condensed', 'Damascus', 'DecoType Naskh', 'DejaVu Sans', 'DejaVu Sans Display', 'DejaVu Sans Mono', 'DejaVu Serif', 'DejaVu Serif Display', 'Devanagari MT', 'Devanagari Sangam MN', 'Didot', 'Diwan Kufi', 'Diwan Thuluth', 'Euphemia UCAS', 'Farah', 'Farisi', 'Futura', 'Galvji', 'Geeza Pro', 'Geneva', 'Georgia', 'Gill Sans', 'Grantha Sangam MN', 'Gujarati MT', 'Gujarati Sangam MN', 'Gurmukhi MN', 'Gurmukhi MT', 'Gurmukhi Sangam MN', 'Heiti SC', 'Heiti TC', 'Helvetica', 'Helvetica Neue', 'Herculanum', 'Hiragino Kaku Gothic Pro', 'Hiragino Kaku Gothic Pro W3', 'Hiragino Kaku Gothic Pro W6', 'Hiragino Kaku Gothic ProN', 'Hiragino Kaku Gothic ProN W3', 'Hiragino Kaku Gothic ProN W6', 'Hiragino Kaku Gothic Std', 'Hiragino Kaku Gothic Std W8', 'Hiragino Kaku Gothic StdN', 'Hiragino Kaku Gothic StdN W8', 'Hiragino Maru Gothic Pro', 'Hiragino Maru Gothic Pro W4', 'Hiragino Maru Gothic ProN', 'Hiragino Maru Gothic ProN W4', 'Hiragino Mincho Pro', 'Hiragino Mincho Pro W3', 'Hiragino Mincho Pro W6', 'Hiragino Mincho ProN', 'Hiragino Mincho ProN W3', 'Hiragino Mincho ProN W6', 'Hiragino Sans', 'Hiragino Sans GB', 'Hiragino Sans GB W3', 'Hiragino Sans GB W6', 'Hiragino Sans W0', 'Hiragino Sans W1', 'Hiragino Sans W2', 'Hiragino Sans W3', 'Hiragino Sans W4', 'Hiragino Sans W5', 'Hiragino Sans W6', 'Hiragino Sans W7', 'Hiragino Sans W8', 'Hiragino Sans W9', 'Hoefler Text', 'Hoefler Text Ornaments', 'ITF Devanagari', 'ITF Devanagari Marathi', 'Impact', 'InaiMathi', 'Iowan Old Style', 'Iowan Old Style Black', 'Kailasa', 'Kannada MN', 'Kannada Sangam MN', 'Kefa III', 'Khmer MN', 'Khmer Sangam MN', 'Kohinoor Bangla', 'Kohinoor Devanagari', 'Kohinoor Gujarati', 'Kohinoor Telugu', 'Kokonor', 'Krungthep', 'KufiStandardGK', 'Lao MN', 'Lao Sangam MN', 'Last Resort High-Efficiency', 'Lucida Grande', 'Luminari', 'Malayalam MN', 'Malayalam Sangam MN', 'Marion', 'Marker Felt', 'Menlo', 'Microsoft Sans Serif', 'Mishafi', 'Mishafi Gold', 'Monaco', 'Mshtakan', 'Mukta Mahee', 'MuktaMahee Bold', 'MuktaMahee ExtraBold', 'MuktaMahee ExtraLight', 'MuktaMahee Light', 'MuktaMahee Medium', 'MuktaMahee Regular', 'MuktaMahee SemiBold', 'Muna', 'Myanmar MN', 'Myanmar Sangam MN', 'Nadeem', 'New Peninim MT', 'Noteworthy', 'Noto Nastaliq Urdu', 'Noto Sans Adlam', 'Noto Sans Armenian', 'Noto Sans Armenian Blk', 'Noto Sans Armenian ExtBd', 'Noto Sans Armenian ExtLt', 'Noto Sans Armenian Light', 'Noto Sans Armenian Med', 'Noto Sans Armenian SemBd', 'Noto Sans Armenian Thin', 'Noto Sans Avestan', 'Noto Sans Bamum', 'Noto Sans Bassa Vah', 'Noto Sans Batak', 'Noto Sans Bhaiksuki', 'Noto Sans Brahmi', 'Noto Sans Buginese', 'Noto Sans Buhid', 'Noto Sans CanAborig', 'Noto Sans Canadian Aboriginal', 'Noto Sans Carian', 'Noto Sans CaucAlban', 'Noto Sans Caucasian Albanian', 'Noto Sans Chakma', 'Noto Sans Cham', 'Noto Sans Coptic', 'Noto Sans Cuneiform', 'Noto Sans Cypriot', 'Noto Sans Duployan', 'Noto Sans EgyptHiero', 'Noto Sans Egyptian Hieroglyphs', 'Noto Sans Elbasan', 'Noto Sans Glagolitic', 'Noto Sans Gothic', 'Noto Sans Gunjala Gondi', 'Noto Sans Hanifi Rohingya', 'Noto Sans HanifiRohg', 'Noto Sans Hanunoo', 'Noto Sans Hatran', 'Noto Sans ImpAramaic', 'Noto Sans Imperial Aramaic', 'Noto Sans InsPahlavi', 'Noto Sans InsParthi', 'Noto Sans Inscriptional Pahlavi', 'Noto Sans Inscriptional Parthian', 'Noto Sans Javanese', 'Noto Sans Kaithi', 'Noto Sans Kannada', 'Noto Sans Kannada Black', 'Noto Sans Kannada ExtraBold', 'Noto Sans Kannada ExtraLight', 'Noto Sans Kannada Light', 'Noto Sans Kannada Medium', 'Noto Sans Kannada SemiBold', 'Noto Sans Kannada Thin', 'Noto Sans Kayah Li', 'Noto Sans Kharoshthi', 'Noto Sans Khojki', 'Noto Sans Khudawadi', 'Noto Sans Lepcha', 'Noto Sans Limbu', 'Noto Sans Linear A', 'Noto Sans Linear B', 'Noto Sans Lisu', 'Noto Sans Lycian', 'Noto Sans Lydian', 'Noto Sans Mahajani', 'Noto Sans Mandaic', 'Noto Sans Manichaean', 'Noto Sans Marchen', 'Noto Sans Masaram Gondi', 'Noto Sans Meetei Mayek', 'Noto Sans MeeteiMayek', 'Noto Sans Mende Kikakui', 'Noto Sans Meroitic', 'Noto Sans Miao', 'Noto Sans Modi', 'Noto Sans Mongolian', 'Noto Sans Mro', 'Noto Sans Multani', 'Noto Sans Myanmar', 'Noto Sans Myanmar Blk', 'Noto Sans Myanmar ExtBd', 'Noto Sans Myanmar ExtLt', 'Noto Sans Myanmar Light', 'Noto Sans Myanmar Med', 'Noto Sans Myanmar SemBd', 'Noto Sans Myanmar Thin', 'Noto Sans NKo', 'Noto Sans Nabataean', 'Noto Sans Nag Mundari', 'Noto Sans New Tai Lue', 'Noto Sans NewTaiLue', 'Noto Sans Newa', 'Noto Sans Ol Chiki', 'Noto Sans Old Hungarian', 'Noto Sans Old Italic', 'Noto Sans Old North Arabian', 'Noto Sans Old Permic', 'Noto Sans Old Persian', 'Noto Sans Old South Arabian', 'Noto Sans Old Turkic', 'Noto Sans OldHung', 'Noto Sans OldNorArab', 'Noto Sans OldPersian', 'Noto Sans OldSouArab', 'Noto Sans Oriya', 'Noto Sans Osage', 'Noto Sans Osmanya', 'Noto Sans Pahawh Hmong', 'Noto Sans Palmyrene', 'Noto Sans Pau Cin Hau', 'Noto Sans PauCinHau', 'Noto Sans PhagsPa', 'Noto Sans Phoenician', 'Noto Sans PsaPahlavi', 'Noto Sans Psalter Pahlavi', 'Noto Sans Rejang', 'Noto Sans Samaritan', 'Noto Sans Saurashtra', 'Noto Sans Sharada', 'Noto Sans Siddham', 'Noto Sans Sora Sompeng', 'Noto Sans SoraSomp', 'Noto Sans Sundanese', 'Noto Sans Syloti Nagri', 'Noto Sans Syriac', 'Noto Sans Tagalog', 'Noto Sans Tagbanwa', 'Noto Sans Tai Le', 'Noto Sans Tai Tham', 'Noto Sans Tai Viet', 'Noto Sans Takri', 'Noto Sans Thaana', 'Noto Sans Tifinagh', 'Noto Sans Tirhuta', 'Noto Sans Ugaritic', 'Noto Sans Vai', 'Noto Sans Wancho', 'Noto Sans Warang Citi', 'Noto Sans WarangCiti', 'Noto Sans Yi', 'Noto Sans Zawgyi', 'Noto Sans Zawgyi Blk', 'Noto Sans Zawgyi ExtBd', 'Noto Sans Zawgyi ExtLt', 'Noto Sans Zawgyi Light', 'Noto Sans Zawgyi Med', 'Noto Sans Zawgyi SemBd', 'Noto Sans Zawgyi Thin', 'Noto Serif Ahom', 'Noto Serif Balinese', 'Noto Serif Hmong Nyiakeng', 'Noto Serif Myanmar', 'Noto Serif Myanmar Blk', 'Noto Serif Myanmar ExtBd', 'Noto Serif Myanmar ExtLt', 'Noto Serif Myanmar Light', 'Noto Serif Myanmar Med', 'Noto Serif Myanmar SemBd', 'Noto Serif Myanmar Thin', 'Noto Serif Yezidi', 'Optima', 'Oriya MN', 'Oriya Sangam MN', 'PT Mono', 'PT Sans', 'PT Sans Caption', 'PT Sans Narrow', 'PT Serif', 'PT Serif Caption', 'Palatino', 'Papyrus', 'Party LET', 'Phosphate', 'Plantagenet Cherokee', 'Raanana', 'Rockwell', 'STIX Two Math', 'STIX Two Text', 'STIXGeneral', 'STIXIntegralsD', 'STIXIntegralsSm', 'STIXIntegralsUp', 'STIXIntegralsUpD', 'STIXIntegralsUpSm', 'STIXNonUnicode', 'STIXSizeFiveSym', 'STIXSizeFourSym', 'STIXSizeOneSym', 'STIXSizeThreeSym', 'STIXSizeTwoSym', 'STIXVariants', 'STSong', 'Sana', 'Sathu', 'Savoye LET', 'Seravek', 'Seravek ExtraLight', 'Seravek Light', 'Seravek Medium', 'Shree Devanagari 714', 'SignPainter', 'SignPainter-HouseScript', 'Silom', 'Sinhala MN', 'Sinhala Sangam MN', 'Skia', 'Snell Roundhand', 'Songti SC', 'Songti TC', 'Sukhumvit Set', 'Superclarendon', 'Symbol', 'System Font', 'Tahoma', 'Tamil MN', 'Tamil Sangam MN', 'Telugu MN', 'Telugu Sangam MN', 'Thonburi', 'Times', 'Times New Roman', 'Trattatello', 'Trebuchet MS', 'Verdana', 'Waseem', 'Webdings', 'Wingdings', 'Wingdings 2', 'Wingdings 3', 'Zapf Dingbats', 'Zapfino', 'cmb10', 'cmex10', 'cmmi10', 'cmr10', 'cmss10', 'cmsy10', 'cmti10', 'cmtt10']
Most journals want Arial or Helvetica. Give a fallback list: a cluster or CI container may not have Arial installed, and matplotlib silently substitutes DejaVu Sans while emitting a findfont warning.
For LaTeX-quality maths without a LaTeX install:
This code completed without producing output.
The script header worth copying
import matplotlib as mpl
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme(style="ticks", context="paper", palette="colorblind")
mpl.rcParams.update({
"pdf.fonttype": 42, "ps.fonttype": 42, "svg.fonttype": "none",
"savefig.bbox": "tight", "savefig.dpi": 300,
"figure.dpi": 110,
"axes.titlelocation": "left",
"font.sans-serif": ["Arial", "Helvetica", "DejaVu Sans"],
})
CONDITION_COLORS = {"control": "#4C72B0", "treated": "#DD8452"}
Six lines that make every figure in the project consistent, publication-sized, colourblind-safe and editable. The CONDITION_COLORS dict belongs here too: see Colormaps and Color.
Precedence
Explicit arguments beat everything:
rcParamsDefault < style sheet < sns.set_theme() < rcParams.update() < call arguments
So ax.plot(x, y, lw=3) overrides lines.linewidth regardless of what you set.
Common mistakes
- Restyling every figure by hand instead of setting defaults once.
plt.style.use("seaborn"): renamed toseaborn-v0_8-*.- Setting rcParams after creating the figure. Most apply at draw time, but figure-level ones like
figure.figsizedo not. #prefix on hex colours in a.mplstylefile. Omit it.- Assuming Arial exists on every machine. Provide fallbacks.
- Not committing the style file, so nobody can reproduce your figures.
sns.set(): deprecated alias; usesns.set_theme().- Global rcParams in a library, silently changing your users' plots. Use a context manager.
See also
Saving Figures · seaborn Themes and Palettes · Axes Styling and Annotation · Colormaps and Color · Applied - Reproducible Environment
Exercise
Write style_probe(fontsize, linewidth, override, top_spine), reading three
numbers and a boolean word from one input line. Record
mpl.rcParams["lines.linewidth"] first, then enter an mpl.rc_context setting
font.size and axes.labelsize to fontsize, lines.linewidth to
linewidth, axes.spines.top to top_spine, and figure.figsize to
(4.0, 3.0). Inside the context create a figure, draw one line that inherits
the width and a second passing lw=override explicitly, and set an x label.
Everything must be measured inside the context, because figure.figsize is one
of the parameters that applies at creation time and not at draw time.
Return four lines: figsize=<w>x<h> from fig.get_size_inches();
default_lw=<a> explicit_lw=<b> read back with get_linewidth() from the two
Line2D artists, which shows that an explicit argument outranks the rcParam;
label_fontsize=<n> top_spine=<bool> from ax.xaxis.label and
ax.spines["top"]; and restored=<bool>, comparing lines.linewidth after
the context with the value recorded before it. Round every number to three
decimals. When override equals linewidth the two widths agree, and
restored must still be True: a global rcParams.update would report
False.
Test cases · 3
| # | via | input | expected stdout |
|---|---|---|---|
| 1 | stdin | 9 1.2 3.0 False | figsize=4.0x3.0 default_lw=1.2 explicit_lw=3.0 label_fontsize=9.0 top_spine=False restored=True |
| 2 | stdin | 12 2.0 2.0 True | figsize=4.0x3.0 default_lw=2.0 explicit_lw=2.0 label_fontsize=12.0 top_spine=True restored=True |
| 3 | stdin | 7 0.8 1.6 False | figsize=4.0x3.0 default_lw=0.8 explicit_lw=1.6 label_fontsize=7.0 top_spine=False restored=True |
Hints · 3
01Hint
`mpl.rc_context(dict)` is a context manager that restores every changed key on exit.
02Hint
`ax.xaxis.label` is the Text artist holding the x label, so `get_fontsize()` reports the resolved size.
03Hint
Read `fig.get_size_inches()` before leaving the context — the figure keeps its size, but measure it where the style applies.