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
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "maxplotlibx"
version = "0.1.5"
version = "0.1.6"
description = "A reproducible plotting module with various backends and export options."
readme = "README.md"
requires-python = ">=3.8"
Expand Down
3 changes: 2 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# pytest.ini
[pytest]
addopts = -ra -q
addopts = -ra -q
pythonpath = src
19 changes: 18 additions & 1 deletion src/maxplotlib/canvas/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,7 +946,24 @@ def show(
layers: list | None = None,
usetex: bool | None = None,
verbose: bool = False,
block: bool = True,
):
"""
Render and display the canvas.

Parameters
----------
block : bool, optional
matplotlib backend only (default: True). Whether to block until
the figure window is closed before returning. Passed straight to
``plt.show(block=...)`` rather than left at its default, because
that default follows ``matplotlib.is_interactive()`` -- which
other imported code (IPython, a prior interactive session) can
flip to True behind this call's back, silently turning off
blocking. Forcing it explicitly is what makes repeated
``canvas.show()`` calls in a loop display one figure at a time
instead of every window appearing together.
"""
if verbose:
print(f"Showing canvas using backend: {backend}")

Expand All @@ -962,7 +979,7 @@ def show(
)
if verbose:
print("Displaying Matplotlib figure...")
plt.show()
plt.show(block=block)
return fig, axes
elif backend == "plotly":
resolved_usetex = self._usetex if usetex is None else usetex
Expand Down
25 changes: 24 additions & 1 deletion src/maxplotlib/tests/test_canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,11 +347,34 @@ def test_canvas_show_uses_matplotlib_show(monkeypatch):

fig, axes = canvas.show()

assert calls == [((), {})]
# block=True is passed explicitly (not left at plt.show()'s own default)
# so a caller looping over several canvases shows them one at a time
# regardless of matplotlib's interactive-mode state.
assert calls == [((), {"block": True})]
assert fig is not None
assert axes is not None


def test_canvas_show_block_false_is_forwarded(monkeypatch):
import matplotlib.pyplot as plt

from maxplotlib import Canvas

calls = []

monkeypatch.setattr(
plt, "show", lambda *args, **kwargs: calls.append((args, kwargs))
)

canvas = Canvas()
subplot = canvas.add_subplot()
subplot.plot([0, 1], [0, 1])

canvas.show(block=False)

assert calls == [((), {"block": False})]


def test_show_canvas_script_invokes_canvas_show(monkeypatch):
import maxplotlib

Expand Down
Loading