diff --git a/packages/python/plotly/plotly/subplots.py b/packages/python/plotly/plotly/subplots.py index 3a62a319fab..6af054941d4 100644 --- a/packages/python/plotly/plotly/subplots.py +++ b/packages/python/plotly/plotly/subplots.py @@ -511,13 +511,13 @@ def _checks(item, defaults): # ### vertical_spacing ### if vertical_spacing is None: - if subplot_titles: + if subplot_titles is not None: vertical_spacing = 0.5 / rows else: vertical_spacing = 0.3 / rows # ### subplot titles ### - if not subplot_titles: + if subplot_titles is None: subplot_titles = [""] * rows * cols # ### column_widths ### diff --git a/packages/python/plotly/plotly/tests/test_core/test_subplots/test_make_subplots.py b/packages/python/plotly/plotly/tests/test_core/test_subplots/test_make_subplots.py index fa11f564941..0b699859c47 100644 --- a/packages/python/plotly/plotly/tests/test_core/test_subplots/test_make_subplots.py +++ b/packages/python/plotly/plotly/tests/test_core/test_subplots/test_make_subplots.py @@ -1542,6 +1542,24 @@ def test_subplot_titles_insets(self): ) self.assertEqual(fig, expected) + def test_subplot_titles_array(self): + # Pass python array + expected = tls.make_subplots( + insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=("", "Inset") + ) + fig = tls.make_subplots( + insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=["", "Inset"] + ) + self.assertEqual(fig, expected) + + def test_subplot_titles_empty(self): + # Pass empty array + expected = tls.make_subplots(insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}]) + fig = tls.make_subplots( + insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=[] + ) + self.assertEqual(fig, expected) + def test_large_columns_no_errors(self): """ Test that creating subplots with a large number of columns, and diff --git a/packages/python/plotly/plotly/tests/test_optional/test_subplots/test_make_subplots.py b/packages/python/plotly/plotly/tests/test_optional/test_subplots/test_make_subplots.py new file mode 100644 index 00000000000..0edcacebd1e --- /dev/null +++ b/packages/python/plotly/plotly/tests/test_optional/test_subplots/test_make_subplots.py @@ -0,0 +1,18 @@ +import numpy as np + +from unittest import TestCase + +import plotly.tools as tls + + +class TestMakeSubplots(TestCase): + def test_subplot_titles_numpy_array(self): + # Pass numpy array + expected = tls.make_subplots( + insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], subplot_titles=("", "Inset") + ) + fig = tls.make_subplots( + insets=[{"cell": (1, 1), "l": 0.7, "b": 0.3}], + subplot_titles=np.array(["", "Inset"]), + ) + self.assertEqual(fig, expected)