From 7718a39f9c23e195ec9334e2e46a05195ab2b06b Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Fri, 15 Sep 2023 13:21:06 -0700 Subject: [PATCH 1/3] Cycle labels --- holoviews/plotting/bokeh/__init__.py | 2 +- holoviews/plotting/mpl/__init__.py | 1 + holoviews/plotting/plotly/__init__.py | 1 + holoviews/tests/plotting/bokeh/test_labels.py | 11 +++++++++++ holoviews/tests/plotting/matplotlib/test_labels.py | 10 ++++++++++ holoviews/tests/plotting/plotly/test_labelplot.py | 11 +++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) diff --git a/holoviews/plotting/bokeh/__init__.py b/holoviews/plotting/bokeh/__init__.py index 3fe818bb42..eb4c03fd3d 100644 --- a/holoviews/plotting/bokeh/__init__.py +++ b/holoviews/plotting/bokeh/__init__.py @@ -204,7 +204,7 @@ def colormap_generator(palette): options.VSpan = Options('style', color=Cycle(), alpha=0.5) options.HSpan = Options('style', color=Cycle(), alpha=0.5) options.Arrow = Options('style', arrow_size=10) -options.Labels = Options('style', text_align='center', text_baseline='middle') +options.Labels = Options('style', text_color=Cycle(), text_align='center', text_baseline='middle') # Graphs options.Graph = Options( diff --git a/holoviews/plotting/mpl/__init__.py b/holoviews/plotting/mpl/__init__.py index 1cad80f7e9..6c019abe77 100644 --- a/holoviews/plotting/mpl/__init__.py +++ b/holoviews/plotting/mpl/__init__.py @@ -270,6 +270,7 @@ def grid_selector(grid): options.VSpan = Options('style', alpha=0.5, facecolor=Cycle()) options.HSpan = Options('style', alpha=0.5, facecolor=Cycle()) options.Spline = Options('style', edgecolor=Cycle()) +options.Labels = Options('style', text_color=Cycle()) options.Arrow = Options('style', color='k', linewidth=2, textsize=13) # Paths diff --git a/holoviews/plotting/plotly/__init__.py b/holoviews/plotting/plotly/__init__.py index 9de23b2c69..d3ec817e66 100644 --- a/holoviews/plotting/plotly/__init__.py +++ b/holoviews/plotting/plotly/__init__.py @@ -135,6 +135,7 @@ # Annotations options.VSpan = Options('style', fillcolor=Cycle(), opacity=0.5) options.HSpan = Options('style', fillcolor=Cycle(), opacity=0.5) +options.Labels = Options('style', color=Cycle()) # Shapes options.Rectangles = Options('style', line_color=dflt_shape_line_color) diff --git a/holoviews/tests/plotting/bokeh/test_labels.py b/holoviews/tests/plotting/bokeh/test_labels.py index 565f4807c8..db8b087c93 100644 --- a/holoviews/tests/plotting/bokeh/test_labels.py +++ b/holoviews/tests/plotting/bokeh/test_labels.py @@ -2,7 +2,9 @@ from holoviews.core.dimension import Dimension from holoviews.element import Labels +from holoviews.core.spaces import HoloMap from holoviews.plotting.bokeh.util import property_to_dict +from holoviews.core.options import Cycle from bokeh.models import LinearColorMapper, CategoricalColorMapper @@ -186,3 +188,12 @@ def test_labels_color_index_color_clash(self): "color_index.\n" ) self.assertEqual(log_msg, warning) + + def test_labels_text_color_cycle(self): + hm = HoloMap( + {i: Labels([ + (0, 0 + i, "Label 1"), + (1, 1 + i, "Label 2") + ]) for i in range(0, 3)} + ).overlay() + assert isinstance(hm[0].opts["text_color"], Cycle) diff --git a/holoviews/tests/plotting/matplotlib/test_labels.py b/holoviews/tests/plotting/matplotlib/test_labels.py index 040f31e4a7..a6216c043a 100644 --- a/holoviews/tests/plotting/matplotlib/test_labels.py +++ b/holoviews/tests/plotting/matplotlib/test_labels.py @@ -3,6 +3,7 @@ from holoviews.core.dimension import Dimension from holoviews.core.spaces import HoloMap from holoviews.element import Labels +from holoviews.core.options import Cycle from holoviews.plotting.util import rgb2hex from .test_plot import TestMPLPlot, mpl_renderer @@ -171,3 +172,12 @@ def test_label_rotation_op_update(self): artist = plot.handles['artist'] self.assertEqual([a.get_rotation() for a in artist], [30, 120, 60]) + + def test_labels_text_color_cycle(self): + hm = HoloMap( + {i: Labels([ + (0, 0 + i, "Label 1"), + (1, 1 + i, "Label 2") + ]) for i in range(0, 3)} + ).overlay() + assert isinstance(hm[0].opts["text_color"], Cycle) diff --git a/holoviews/tests/plotting/plotly/test_labelplot.py b/holoviews/tests/plotting/plotly/test_labelplot.py index bf66aa66f5..365b71448a 100644 --- a/holoviews/tests/plotting/plotly/test_labelplot.py +++ b/holoviews/tests/plotting/plotly/test_labelplot.py @@ -1,6 +1,8 @@ import numpy as np from holoviews.element import Labels, Tiles +from holoviews.core.options import Cycle +from holoviews.core.spaces import HoloMap from .test_plot import TestPlotlyPlot @@ -132,3 +134,12 @@ def test_visible(self): element = Tiles("") * Labels([(0, 3, 0), (1, 2, 1), (2, 1, 1)]).opts(visible=False) state = self._get_plot_state(element) self.assertEqual(state['data'][1]['visible'], False) + + def test_labels_text_color_cycle(self): + hm = HoloMap( + {i: Labels([ + (0, 0 + i, "Label 1"), + (1, 1 + i, "Label 2") + ]) for i in range(0, 3)} + ).overlay() + assert isinstance(hm[0].opts["text_color"], Cycle) From 8752225e8dabb35dddbf1b9dc818b7521d18c8eb Mon Sep 17 00:00:00 2001 From: Andrew Huang Date: Fri, 15 Sep 2023 13:28:42 -0700 Subject: [PATCH 2/3] Fix backends --- holoviews/plotting/mpl/__init__.py | 2 +- holoviews/tests/plotting/matplotlib/test_labels.py | 2 +- holoviews/tests/plotting/plotly/test_labelplot.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/holoviews/plotting/mpl/__init__.py b/holoviews/plotting/mpl/__init__.py index 6c019abe77..d1da8372d2 100644 --- a/holoviews/plotting/mpl/__init__.py +++ b/holoviews/plotting/mpl/__init__.py @@ -270,7 +270,7 @@ def grid_selector(grid): options.VSpan = Options('style', alpha=0.5, facecolor=Cycle()) options.HSpan = Options('style', alpha=0.5, facecolor=Cycle()) options.Spline = Options('style', edgecolor=Cycle()) -options.Labels = Options('style', text_color=Cycle()) +options.Labels = Options('style', color=Cycle()) options.Arrow = Options('style', color='k', linewidth=2, textsize=13) # Paths diff --git a/holoviews/tests/plotting/matplotlib/test_labels.py b/holoviews/tests/plotting/matplotlib/test_labels.py index a6216c043a..403da1dc35 100644 --- a/holoviews/tests/plotting/matplotlib/test_labels.py +++ b/holoviews/tests/plotting/matplotlib/test_labels.py @@ -180,4 +180,4 @@ def test_labels_text_color_cycle(self): (1, 1 + i, "Label 2") ]) for i in range(0, 3)} ).overlay() - assert isinstance(hm[0].opts["text_color"], Cycle) + assert isinstance(hm[0].opts["color"], Cycle) diff --git a/holoviews/tests/plotting/plotly/test_labelplot.py b/holoviews/tests/plotting/plotly/test_labelplot.py index 365b71448a..dc2dcc3e88 100644 --- a/holoviews/tests/plotting/plotly/test_labelplot.py +++ b/holoviews/tests/plotting/plotly/test_labelplot.py @@ -142,4 +142,4 @@ def test_labels_text_color_cycle(self): (1, 1 + i, "Label 2") ]) for i in range(0, 3)} ).overlay() - assert isinstance(hm[0].opts["text_color"], Cycle) + assert isinstance(hm[0].opts["color"], Cycle) From 80bc964ff51e360d34fc81c0d33f128dab136005 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20H=C3=B8xbro=20Hansen?= Date: Mon, 18 Sep 2023 09:50:26 +0200 Subject: [PATCH 3/3] Apply suggestions from code review --- holoviews/tests/plotting/bokeh/test_labels.py | 2 +- holoviews/tests/plotting/matplotlib/test_labels.py | 2 +- holoviews/tests/plotting/plotly/test_labelplot.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/holoviews/tests/plotting/bokeh/test_labels.py b/holoviews/tests/plotting/bokeh/test_labels.py index db8b087c93..ffdc2f15f1 100644 --- a/holoviews/tests/plotting/bokeh/test_labels.py +++ b/holoviews/tests/plotting/bokeh/test_labels.py @@ -194,6 +194,6 @@ def test_labels_text_color_cycle(self): {i: Labels([ (0, 0 + i, "Label 1"), (1, 1 + i, "Label 2") - ]) for i in range(0, 3)} + ]) for i in range(3)} ).overlay() assert isinstance(hm[0].opts["text_color"], Cycle) diff --git a/holoviews/tests/plotting/matplotlib/test_labels.py b/holoviews/tests/plotting/matplotlib/test_labels.py index 403da1dc35..4ae9c4a78f 100644 --- a/holoviews/tests/plotting/matplotlib/test_labels.py +++ b/holoviews/tests/plotting/matplotlib/test_labels.py @@ -178,6 +178,6 @@ def test_labels_text_color_cycle(self): {i: Labels([ (0, 0 + i, "Label 1"), (1, 1 + i, "Label 2") - ]) for i in range(0, 3)} + ]) for i in range(3)} ).overlay() assert isinstance(hm[0].opts["color"], Cycle) diff --git a/holoviews/tests/plotting/plotly/test_labelplot.py b/holoviews/tests/plotting/plotly/test_labelplot.py index dc2dcc3e88..6c510001ed 100644 --- a/holoviews/tests/plotting/plotly/test_labelplot.py +++ b/holoviews/tests/plotting/plotly/test_labelplot.py @@ -140,6 +140,6 @@ def test_labels_text_color_cycle(self): {i: Labels([ (0, 0 + i, "Label 1"), (1, 1 + i, "Label 2") - ]) for i in range(0, 3)} + ]) for i in range(3)} ).overlay() assert isinstance(hm[0].opts["color"], Cycle)