Skip to content

Commit

Permalink
fixed bug with extend and append
Browse files Browse the repository at this point in the history
  • Loading branch information
Davide-sd committed Jul 9, 2023
1 parent cb3a046 commit a75b4a2
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 4 additions & 0 deletions spb/backends/base_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ def append(self, arg):
self.legend = True
else:
raise TypeError("Must specify element of plot to append.")
# recreate renderers
self._create_renderers()

def extend(self, arg):
"""Adds all series from another plot.
Expand Down Expand Up @@ -664,3 +666,5 @@ def extend(self, arg):
# auto legend
if len(self._series) > 1:
self.legend = True
# recreate renderers
self._create_renderers()
26 changes: 25 additions & 1 deletion tests/backends/test_base_backend.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from spb.backends.base_backend import Plot
from spb.series import BaseSeries
from spb.series import BaseSeries, HVLineSeries
from pytest import raises
import matplotlib
import matplotlib.pyplot as plt
Expand Down Expand Up @@ -178,3 +178,27 @@ def test_xaxis_inverted():
ylim=(-1.25, 1.25), backend=MB, use_latex=False, show=False, n=10
)
p.backend.draw()


def test_number_of_renderers():
# verify that once `extend` or `append` is executed, the number of
# renderers will be equal to the new number of series

x = symbols("x")
hor = HVLineSeries(0, True, show_in_legend=False)
ver1 = HVLineSeries(0, False, show_in_legend=False)
ver2 = HVLineSeries(1, False, show_in_legend=False)

def do_test(B):
p = plot(sin(x), (x, -5, 5), backend=B, show=False, n=5)
assert len(p.series) == len(p.renderers) == 1

p.extend([hor, ver1])
assert len(p.series) == len(p.renderers) == 3

p.append(ver2)
assert len(p.series) == len(p.renderers) == 4

do_test(MB)
do_test(PB)
do_test(BB)

0 comments on commit a75b4a2

Please sign in to comment.