Skip to content

Commit 44fca01

Browse files
committed
Do not return anything when running show with plotly
1 parent c61522f commit 44fca01

4 files changed

Lines changed: 86 additions & 63 deletions

File tree

‎src/maxplotlib/canvas/canvas.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2059,7 +2059,9 @@ def show(
20592059
allow_unsupported=allow_unsupported,
20602060
)
20612061
fig.show()
2062-
return fig
2062+
# Plotly has already displayed the figure. Returning it from a
2063+
# notebook cell would trigger a second implicit rich display.
2064+
return None if _running_in_jupyter() else fig
20632065
elif backend == "plotext":
20642066
figure = self.plot_plotext(
20652067
savefig=False,

‎src/maxplotlib/tests/test_canvas.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,27 @@ def test_canvas_show_uses_matplotlib_show(monkeypatch):
411411
assert axes is not None
412412

413413

414+
def test_canvas_show_plotly_does_not_return_displayed_figure_in_jupyter(monkeypatch):
415+
import maxplotlib.canvas.canvas as canvas_module
416+
from maxplotlib import Canvas
417+
418+
class FakePlotlyFigure:
419+
def __init__(self):
420+
self.show_calls = 0
421+
422+
def show(self):
423+
self.show_calls += 1
424+
425+
figure = FakePlotlyFigure()
426+
monkeypatch.setattr(Canvas, "plot_plotly", lambda *args, **kwargs: figure)
427+
monkeypatch.setattr(canvas_module, "_running_in_jupyter", lambda: True)
428+
429+
result = Canvas().show(backend="plotly")
430+
431+
assert result is None
432+
assert figure.show_calls == 1
433+
434+
414435
def test_canvas_show_uses_ipython_display_in_jupyter(monkeypatch):
415436
import sys
416437
import types

0 commit comments

Comments
 (0)