Skip to content

fix(plotting): add show=True parameter to PlotMethods for blocking display in scripts#831

Open
tanishkasinghhh wants to merge 1 commit into
camelot-dev:masterfrom
tanishkasinghhh:fix/plot-show-blocking-296
Open

fix(plotting): add show=True parameter to PlotMethods for blocking display in scripts#831
tanishkasinghhh wants to merge 1 commit into
camelot-dev:masterfrom
tanishkasinghhh:fix/plot-show-blocking-296

Conversation

@tanishkasinghhh

Copy link
Copy Markdown

Problem

camelot.plot(table).show() calls matplotlib's Figure.show(), which
returns immediately in non-interactive (Agg / script) backends — the
window closes before the user can see it (issue #296).

The correct blocking entry point for scripts is plt.show(block=True).
However, Figure.show() does not accept a block argument, so users
cannot work around it without calling plt.show() separately — and this
is not obvious from the camelot API.

Fix

Add show=False to PlotMethods.__call__(). When show=True, call
plt.show(block=True) after creating the figure.

# Before — window closes immediately in scripts
fig = camelot.plot(tables[0], kind='grid')
fig.show()   # Figure.show(), non-blocking

# After — window stays open until the user closes it
fig = camelot.plot(tables[0], kind='grid', show=True)

The default is False to preserve existing behaviour for all callers
(Jupyter notebooks, image-comparison tests, file-save paths).

Changes

File What
camelot/plotting.py Add show=False kwarg; call plt.show(block=True) when set (only on non-filename paths)
tests/test_plot_show.py 4 unit tests: verify plt.show not called by default; called with block=True when requested; figure is still returned; save-to-file path unaffected

Tests

pytest tests/test_plot_show.py -v
# 4 passed — fails before fix (TypeError: unexpected keyword argument 'show')

Closes #296

Prepared with AI assistance (Claude Code). Every change reviewed and understood line-by-line.

…play in scripts

camelot.plot(table).show() calls matplotlib's Figure.show(), which
returns immediately in non-interactive (Agg / script) backends — the
window closes before the user sees it (issue camelot-dev#296).

The correct entry point for blocking display in a plain Python script is
plt.show(block=True).  Users reported that passing block=True to the
Figure directly raised TypeError, because Figure.show() does not accept
that argument.

Fix: add show=False to PlotMethods.__call__().  When show=True, call
plt.show(block=True) after creating the figure.  The default remains
False so all existing callers (Jupyter notebooks, image-comparison tests,
file-save paths) are unaffected.

Usage after this change:

    fig = camelot.plot(tables[0], kind='grid', show=True)

Closes camelot-dev#296
@bosd

bosd commented Jul 18, 2026

Copy link
Copy Markdown
Collaborator

Triage: the failing check here is pre-commit, not the test suite — all the tests jobs (3.10–3.14, Windows, macOS) pass. So the plotting change itself is fine; it's a lint/format gate.

Two things ruff flags in the new test file:

  1. S108 (×2, unfixable auto)Probable insecure usage of temporary file: "/tmp/out.png". Hardcoded /tmp/... paths trip flake8-bandit. Fix by using pytest's tmp_path fixture instead:
    def test_...(tmp_path):
        out = tmp_path / "out.png"
        ...
        mock_fig.savefig.assert_called_once_with(str(out))
  2. ruff-format — one file needs reformatting; run pre-commit run --all-files (or ruff format) locally and commit.

pre-commit is a hard-required gate here, so once those two are addressed CI should go green. The show=True design itself looks reasonable for #296. Thanks for the contribution, @tanishkasinghhh!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

show() not showing anything

2 participants