Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ Do not commit or push if either fails. Fix issues first.
tick labels, axis labels, axes and figure titles, figure-level axis labels, and the legend and
its title. Do not give any of them another size or weight.
- It saves at 600 dpi (`savefig.dpi`), embeds TrueType fonts in PDF and PostScript
(`pdf.fonttype` and `ps.fonttype` 42), stores SVG text as paths, and sets no figure size.
(`pdf.fonttype` and `ps.fonttype` 42), stores SVG text as paths, sets no figure size, and does
not crop saved figures (no `savefig.bbox`), so a saved file has exactly the figure's size.
- A change to the style goes together with the "What the style changes" table in `README.md` and
the assertions in `tests/test_styles.py`.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ the `stylelib/` folder of your Matplotlib config directory (`matplotlib.get_conf

| Area | Settings |
| --- | --- |
| Figure | No figure size is set. Saved at 600 dpi and shown on screen at 300 dpi. `savefig` crops to a tight bounding box. |
| Figure | No figure size is set. Saved at 600 dpi and shown on screen at 300 dpi. Saved files are not cropped, so they keep the figure's size; pass `bbox_inches="tight"` to `savefig` to crop to the drawn content. |
| Text | Arial Regular 8 pt (see [Fonts](#fonts)) for every text element: tick labels, axis labels, axes and figure titles, and the legend and its title. Math text (`$...$`) uses the same font. |
| Vector output | PDF and PostScript embed fonts as TrueType (Type 42), so text stays editable and passes journal checks that reject Type 3 fonts. SVG stores glyphs as paths. |
| Axes | 1.5 pt axis lines, with the top and right spines removed. Autoscaled limits are rounded out to tick values. |
Expand Down
4 changes: 2 additions & 2 deletions src/mplplots/styles/GraphPadPrism.mplstyle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ axes.titleweight: normal

errorbar.capsize: 3

# Screen resolution; saved files use savefig.dpi. The style sets no figure size.
# Screen resolution; saved files use savefig.dpi. The style sets no figure size and does not
# crop saved figures (no savefig.bbox), so a saved file has exactly the figure's size.
figure.dpi: 300
figure.frameon: False
figure.labelsize: 8
Expand Down Expand Up @@ -55,7 +56,6 @@ mathtext.sf: sans
pdf.fonttype: 42
ps.fonttype: 42

savefig.bbox: tight
savefig.dpi: 600

# SVG stores glyphs as paths, so it looks the same on machines without Arial.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,18 @@ def test_style_sets_dpi(self) -> None:
assert matplotlib.rcParams["figure.dpi"] == 300
assert matplotlib.rcParams["savefig.dpi"] == 600

def test_saved_figure_keeps_its_size(self) -> None:
# No tight bounding box: the file is the whole figure, so it keeps the figure's size.
with plt.style.context(GRAPHPAD_STYLE):
fig, ax = plt.subplots(figsize=(2, 1.5))
ax.plot([1, 2], [1, 2])
buffer = io.BytesIO()
fig.savefig(buffer, format="png", dpi=100)
plt.close(fig)
buffer.seek(0)
height, width = plt.imread(buffer).shape[:2]
assert (width, height) == (200, 150)

def test_style_sets_no_figure_size(self) -> None:
with plt.rc_context({"figure.figsize": (1.5, 2.5)}), plt.style.context(GRAPHPAD_STYLE):
assert list(matplotlib.rcParams["figure.figsize"]) == [1.5, 2.5]
Expand Down
Loading