Quick Startยถ
A minimal end-to-end workflow: apply a style, create a figure, and export it.
Hereโs a typical matplotlib figure, then the same figure with dartwork-mpl:
import matplotlib.pyplot as plt
import dartwork_mpl as dm
import numpy as np
dm.style.use("scientific") # curated fonts, colors, line weights
fig, ax = plt.subplots(figsize=(dm.cm2in(15), dm.cm2in(10)), dpi=300)
x = np.linspace(0, 10, 200)
ax.plot(x, np.sin(x), color="oc.blue5", label="signal", lw=dm.lw(1.5))
ax.set_xticks(np.arange(0, 11, 2))
ax.set_xlabel("Time [s]", fontsize=dm.fs(0))
ax.set_ylabel("Amplitude", fontsize=dm.fs(0))
ax.legend(fontsize=dm.fs(-1))
dm.simple_layout(fig) # auto-optimize margins
dm.save_and_show(fig, size=720) # preview at 720px wide + save
import matplotlib.pyplot as plt
import numpy as np
fig, ax = plt.subplots(figsize=(2.95, 1.97), dpi=300)
x = np.linspace(0, 10, 200)
ax.plot(x, np.sin(x), color="#1c7ed6", label="signal", lw=1.5)
ax.set_xticks(np.arange(0, 11, 2))
ax.set_xlabel("Time [s]", fontsize=7.5)
ax.set_ylabel("Amplitude", fontsize=7.5)
ax.legend(fontsize=6.5)
fig.tight_layout()
fig.savefig("output.png", dpi=300, bbox_inches="tight")
plt.show()
The same chart rendered with dm.style.use("scientific") โ professional typography, optimized margins, and named colors.ยถ
Drag the slider to compare โ same data, different styling:
Same data, same plotting logic โ the difference is one dm.style.use() call, named colors, and simple_layout.
What each dartwork-mpl call does:
Call |
Purpose |
|---|---|
|
Sets palette, fonts, line weights โ see Styles |
|
Converts 9 cm to inches for |
|
Returns the base font size of the active preset ( |
|
Auto-optimizes margins (replaces |
|
Preview at 720 px wide in the notebook, then call |
Creating Figures with Stylesยถ
dartwork-mpl provides dm.subplots() and dm.figure() wrappers that apply
styles during figure creation:
# Apply style automatically when creating figure
fig, ax = dm.subplots(style='scientific')
# Stack multiple styles
fig, axes = dm.subplots(2, 2, style=['font-libertine', 'theme-dark'])
# Override style defaults
fig, ax = dm.subplots(style='report', figsize=(10, 6), dpi=150)
These functions follow the Zero-Resize Policy: when you specify a style, figsize and dpi are determined by the style unless explicitly overridden.
Comparison with standard matplotlib:
# Standard matplotlib approach
plt.style.use('seaborn')
fig, ax = plt.subplots(figsize=(8, 6), dpi=100)
# dartwork-mpl approach - more concise
fig, ax = dm.subplots(style='scientific', figsize=(8, 6), dpi=100)
Multi-panel figures with automatic styling:
# Create 2x2 grid with custom ratios
fig, axes = dm.subplots(2, 2,
style='scientific',
width_ratios=[2, 1],
height_ratios=[1, 2])
for ax in axes.flat:
ax.plot(np.random.randn(100))
dm.simple_layout(fig)
Adding colorยถ
dartwork-mpl registers named colors from several design systems. Use them anywhere matplotlib accepts a color string:
# Named color prefixes
ax.plot(x, y, color="oc.blue5") # OpenColor
ax.fill_between(x, y1, y2, color="tw.emerald200") # Tailwind
ax.bar(categories, values, color="md.red500") # Material Design
See Colors and Colormaps for the full palette reference.
Multi-panel layoutยถ
import matplotlib.pyplot as plt
import dartwork_mpl as dm
import numpy as np
dm.style.use("presentation")
x = np.linspace(0, 10, 100)
fig = plt.figure(figsize=(dm.cm2in(15), dm.cm2in(8.5)), dpi=300)
gs = fig.add_gridspec(1, 2, wspace=0.3)
ax1 = fig.add_subplot(gs[0])
ax2 = fig.add_subplot(gs[1])
ax1.plot(x, np.sin(x), color="oc.red5")
ax2.plot(x, np.cos(x), color="oc.blue5")
dm.label_axes([ax1, ax2]) # adds (a), (b) panel labels
dm.simple_layout(fig, gs=gs)
Saving in multiple formatsยถ
dm.save_formats(
fig,
"output/my_figure",
formats=("png", "svg", "pdf"),
dpi=300,
validate=True, # auto-check for overflow, overlap, etc.
)
Next stepsยถ
Choose the right preset for your use case โ papers, reports, slides, posters.
โ Browse presets
Explore 900+ named palettes and perceptual OKLCH interpolation.
โ See palettes
Panel labels, arrows, font scaling, and margin optimization.
โ Learn layout