Below is a self-contained, publication-ready Matplotlib parameter template that you can drop into any Python script or notebook.
It is split into two parts:
- A reusable style dictionary (
PUB_STYLE) that can be applied globally or per-figure.
- A short demonstration that generates three random examples (scatter, line, and bar) using the same style.
Save the code block as pub_template.py (or run it in a notebook) and adapt the data or layout calls as needed.
"""
pub_template.py
Publication-ready Matplotlib style template with random examples.
Author: <Your Name>
Date: <Today>
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rcParams
from cycler import cycler
# ------------------------------------------------------------------
# 1. PUBLICATION STYLE DICTIONARY
# ------------------------------------------------------------------
PUB_STYLE = {
# Figure and axes
"figure.figsize": (3.5, 2.2), # Single-column width (inches)
"figure.dpi": 300,
"savefig.dpi": 600,
"savefig.bbox": "tight",
"savefig.pad_inches": 0.02,
# Font
"font.family": "serif",
"font.serif": ["Times New Roman"],
"mathtext.fontset": "stix",
"font.size": 8,
"axes.titlesize": 9,
"axes.labelsize": 8,
"xtick.labelsize": 7,
"ytick.labelsize": 7,
"legend.fontsize": 7,
"legend.title_fontsize": 7,
# Lines and markers
"lines.linewidth": 1.0,
"lines.markersize": 3,
"lines.markeredgewidth": 0.3,
# Axes
"axes.linewidth": 0.6,
"axes.prop_cycle": cycler(color=[
"#1f77b4", "#ff7f0e", "#2ca02c", "#d62728", "#9467bd",
"#8c564b", "#e377c2", "#7f7f7f", "#bcbd22", "#17becf"
]),
"axes.spines.top": False,
"axes.spines.right": False,
"axes.xmargin": 0.02,
"axes.ymargin": 0.02,
# Ticks
"xtick.direction": "in",
"ytick.direction": "in",
"xtick.major.size": 2.5,
"ytick.major.size": 2.5,
"xtick.minor.size": 1.5,
"ytick.minor.size": 1.5,
"xtick.major.width": 0.4,
"ytick.major.width": 0.4,
"xtick.minor.width": 0.3,
"ytick.minor.width": 0.3,
"xtick.minor.visible": True,
"ytick.minor.visible": True,
# Grid
"axes.grid": False,
# Legend
"legend.frameon": False,
"legend.handletextpad": 0.4,
"legend.columnspacing": 1.0,
}
# Apply globally (optional)
rcParams.update(PUB_STYLE)
# ------------------------------------------------------------------
# 2. RANDOM EXAMPLES
# ------------------------------------------------------------------
np.random.seed(42)
def example_scatter():
x = np.random.normal(0, 1, 60)
y = 1.2 * x + np.random.normal(0, 0.5, 60)
fig, ax = plt.subplots()
ax.scatter(x, y, c="#1f77b4", label="Data")
ax.set_xlabel(r"$x$")
ax.set_ylabel(r"$y$")
ax.set_title("Scatter Example")
ax.legend()
fig.savefig("scatter_example.pdf")
return fig, ax
def example_line():
t = np.linspace(0, 4 * np.pi, 200)
y1 = np.sin(t)
y2 = np.cos(t)
fig, ax = plt.subplots()
ax.plot(t, y1, label=r"$\sin(t)$")
ax.plot(t, y2, label=r"$\cos(t)$")
ax.set_xlabel(r"$t$")
ax.set_ylabel(r"$y$")
ax.set_title("Line Example")
ax.legend()
fig.savefig("line_example.pdf")
return fig, ax
def example_bar():
categories = ["A", "B", "C", "D"]
means = np.random.uniform(2, 5, len(categories))
errs = np.random.uniform(0.1, 0.3, len(categories))
fig, ax = plt.subplots()
ax.bar(categories, means, yerr=errs, capsize=2, color="#2ca02c")
ax.set_ylabel("Mean Value")
ax.set_title("Bar Example")
fig.savefig("bar_example.pdf")
return fig, ax
# ------------------------------------------------------------------
# Run examples
# ------------------------------------------------------------------
if __name__ == "__main__":
example_scatter()
example_line()
example_bar()
plt.show()
Usage notes
- Single vs. double column: Change
figure.figsize to (7.2, 4.5) for a two-column width figure.
- Fonts: If Times New Roman is unavailable, substitute with
"DejaVu Serif" or any serif font installed on your system.
- Vector output: The template saves PDFs by default; switch to
.svg or .eps if the journal prefers those formats.
- Reproducibility: The random seed is fixed (
np.random.seed(42)) so the examples are reproducible.