Configuration¶
Process-wide defaults for dartwork-mpl behaviour toggles. Mutate the
config singleton once near the top of your program
to flip the default of every call site that reads it — without having
to thread the keyword through each individual call.
Per-call keyword arguments always win over the global default.
Example¶
import matplotlib.pyplot as plt
import dartwork_mpl as dm
dm.style.use("scientific")
# Flip orphan-tick adoption off globally.
dm.config.adopt_orphan_tick_font = False
fig, ax = plt.subplots(figsize=dm.figsize("13cm", "standard"))
ax.plot([1, 2, 3], [1, 4, 9]) # no axis label on x
dm.simple_layout(fig) # tick fonts left untouched
dm.save_formats(fig, "out", formats=("png",)) # also untouched
# Per-call override still works.
dm.simple_layout(fig, adopt_orphan_tick_font=True)
# Or scope the change to a block.
with dm.config.override(adopt_orphan_tick_font=True):
dm.save_formats(fig, "out", formats=("png",))
API¶
- class dartwork_mpl.Config(adopt_orphan_tick_font: bool = True, warn_on_orphan_tick_adoption: bool = False)[source]¶
Process-wide dartwork-mpl defaults.
Slotted so a typo’d direct assignment (
dm.config.adopt_orphan_tick_fonts = False— note the plural) raisesAttributeErrorinstead of silently creating a dead attribute that never affects behaviour.- adopt_orphan_tick_font¶
Fallback default for the
adopt_orphan_tick_fontkeyword ondartwork_mpl.simple_layout(),dartwork_mpl.save_formats(), anddartwork_mpl.save_and_show(). Each of those functions acceptsTrue/False/None(the call-site default);Noneis read here. Set this toFalseto leave orphan-axis tick fonts alone everywhere by default. Per-call overrides (passingTrue/Falseexplicitly) still win.- Type:
bool, default
True
- warn_on_orphan_tick_adoption¶
When
True, emit a one-timeUserWarningevery time orphan-tick font adoption mutates a figure (viadartwork_mpl.layout.adopt_axis_label_font()or its driverssimple_layout(),save_formats(),save_and_show()). Useful when debugging a figure whose ticks change unexpectedly after a save — or when running under matplotlib’sconstrained_layout, where the font change can trigger a re-layout on the next draw. Default is off so the common path stays quiet.- Type:
bool, default
False
- override(**overrides: object) Iterator[None][source]¶
Temporarily override one or more defaults inside a
withblock.Restores every overridden field to its previous value on exit — including the exception path. Raises
AttributeErrorfor any keyword that is not an existingConfigfield, so a typo can’t silently shadow the singleton with a new attribute.- Parameters:
**overrides –
field_name=valuepairs. Every name must already exist onConfig.- Yields:
None – The block runs with the overridden defaults active.
Example
with dm.config.override(adopt_orphan_tick_font=False): dm.simple_layout(fig) # adoption skipped just here dm.simple_layout(fig) # adoption re-applied (back to default)
- dartwork_mpl.config¶
Process-wide dartwork-mpl defaults.
Slotted so a typo’d direct assignment (
dm.config.adopt_orphan_tick_fonts = False— note the plural) raisesAttributeErrorinstead of silently creating a dead attribute that never affects behaviour.- dartwork_mpl.adopt_orphan_tick_font¶
Fallback default for the
adopt_orphan_tick_fontkeyword ondartwork_mpl.simple_layout(),dartwork_mpl.save_formats(), anddartwork_mpl.save_and_show(). Each of those functions acceptsTrue/False/None(the call-site default);Noneis read here. Set this toFalseto leave orphan-axis tick fonts alone everywhere by default. Per-call overrides (passingTrue/Falseexplicitly) still win.- Type:
bool, default
True
- dartwork_mpl.warn_on_orphan_tick_adoption¶
When
True, emit a one-timeUserWarningevery time orphan-tick font adoption mutates a figure (viadartwork_mpl.layout.adopt_axis_label_font()or its driverssimple_layout(),save_formats(),save_and_show()). Useful when debugging a figure whose ticks change unexpectedly after a save — or when running under matplotlib’sconstrained_layout, where the font change can trigger a re-layout on the next draw. Default is off so the common path stays quiet.- Type:
bool, default
False