From 7adcf29ca7eda26535a939cbb5f4ef3fa26fae9c Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:45:01 -0300 Subject: [PATCH 01/12] Adding Scalar as a Baseline Option --- lib/matplotlib/stackplot.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 4e933f52887d..9a6238376577 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -32,7 +32,7 @@ def stackplot(axes, x, *args, stackplot(x, y) # where y has shape (M, N) stackplot(x, y1, y2, y3) # where y1, y2, y3, y4 have length N - baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle'} + baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle', int} Method used to calculate the baseline: - ``'zero'``: Constant zero baseline, i.e. a simple stacked plot. @@ -42,6 +42,7 @@ def stackplot(axes, x, *args, - ``'weighted_wiggle'``: Does the same but weights to account for size of each layer. It is also called 'Streamgraph'-layout. More details can be found at http://leebyron.com/streamgraph/. + - ``int``: Scalar baseline. Useful for cases where 0 is not sensible. labels : list of str, optional A sequence of labels to assign to each data series. If unspecified, @@ -94,8 +95,9 @@ def stackplot(axes, x, *args, # We'll need a float buffer for the upcoming calculations. stack = np.cumsum(y, axis=0, dtype=np.promote_types(y.dtype, np.float32)) - _api.check_in_list(['zero', 'sym', 'wiggle', 'weighted_wiggle'], - baseline=baseline) + if isinstance(baseline, int) != True: + _api.check_in_list(['zero', 'sym', 'wiggle', 'weighted_wiggle'], + baseline=baseline) if baseline == 'zero': first_line = 0. @@ -125,6 +127,10 @@ def stackplot(axes, x, *args, first_line = center - 0.5 * total stack += first_line + else: + # Here we are 100% certain that baseline is an integer + first_line = baseline. + # Color between x = 0 and the first array. coll = axes.fill_between(x, first_line, stack[0, :], facecolor=next(colors), From a1e9245d1663dec19a3f1f1239775b9d59320256 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Sun, 12 Nov 2023 15:55:07 -0300 Subject: [PATCH 02/12] fixing linting and casting issue --- lib/matplotlib/stackplot.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 9a6238376577..b43fb824f8df 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -95,9 +95,9 @@ def stackplot(axes, x, *args, # We'll need a float buffer for the upcoming calculations. stack = np.cumsum(y, axis=0, dtype=np.promote_types(y.dtype, np.float32)) - if isinstance(baseline, int) != True: + if not isinstance(baseline, int): _api.check_in_list(['zero', 'sym', 'wiggle', 'weighted_wiggle'], - baseline=baseline) + baseline=baseline) if baseline == 'zero': first_line = 0. @@ -129,7 +129,7 @@ def stackplot(axes, x, *args, else: # Here we are 100% certain that baseline is an integer - first_line = baseline. + first_line = float(baseline) # Color between x = 0 and the first array. coll = axes.fill_between(x, first_line, stack[0, :], From e7d6e404e16261f14d3e699b639cda3b1adef29d Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:36:31 -0300 Subject: [PATCH 03/12] adding float acceptance --- lib/matplotlib/stackplot.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index b43fb824f8df..f0ff645334a8 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -32,7 +32,7 @@ def stackplot(axes, x, *args, stackplot(x, y) # where y has shape (M, N) stackplot(x, y1, y2, y3) # where y1, y2, y3, y4 have length N - baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle', int} + baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle', float} Method used to calculate the baseline: - ``'zero'``: Constant zero baseline, i.e. a simple stacked plot. @@ -42,7 +42,7 @@ def stackplot(axes, x, *args, - ``'weighted_wiggle'``: Does the same but weights to account for size of each layer. It is also called 'Streamgraph'-layout. More details can be found at http://leebyron.com/streamgraph/. - - ``int``: Scalar baseline. Useful for cases where 0 is not sensible. + - ``float``: Scalar baseline. Useful for cases where 0 is not sensible. labels : list of str, optional A sequence of labels to assign to each data series. If unspecified, @@ -95,7 +95,7 @@ def stackplot(axes, x, *args, # We'll need a float buffer for the upcoming calculations. stack = np.cumsum(y, axis=0, dtype=np.promote_types(y.dtype, np.float32)) - if not isinstance(baseline, int): + if isinstance(baseline, str): _api.check_in_list(['zero', 'sym', 'wiggle', 'weighted_wiggle'], baseline=baseline) if baseline == 'zero': @@ -128,7 +128,7 @@ def stackplot(axes, x, *args, stack += first_line else: - # Here we are 100% certain that baseline is an integer + # Here we are 100% certain that baseline is not a string first_line = float(baseline) # Color between x = 0 and the first array. From 15dc450cd03f522e2c2383424c82aab04d75ce22 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:43:53 -0300 Subject: [PATCH 04/12] adding documentation --- lib/matplotlib/stackplot.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index f0ff645334a8..f6ced2c92d6f 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -43,6 +43,7 @@ def stackplot(axes, x, *args, size of each layer. It is also called 'Streamgraph'-layout. More details can be found at http://leebyron.com/streamgraph/. - ``float``: Scalar baseline. Useful for cases where 0 is not sensible. + Any type that can be casted to float is accepted (int, float, bool and custom data objects) labels : list of str, optional A sequence of labels to assign to each data series. If unspecified, From fb74df9a9b48cdc4c11a9d09554d19f8f5dc0f57 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:46:03 -0300 Subject: [PATCH 05/12] fixing large line --- lib/matplotlib/stackplot.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index f6ced2c92d6f..4975373bd05b 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -43,7 +43,8 @@ def stackplot(axes, x, *args, size of each layer. It is also called 'Streamgraph'-layout. More details can be found at http://leebyron.com/streamgraph/. - ``float``: Scalar baseline. Useful for cases where 0 is not sensible. - Any type that can be casted to float is accepted (int, float, bool and custom data objects) + Any type that can be casted to float is accepted + (int, float, bool and custom data objects) labels : list of str, optional A sequence of labels to assign to each data series. If unspecified, From 80a16f250da236f3ca42a6eddfefd8b128d704bb Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Sun, 19 Nov 2023 14:55:54 -0300 Subject: [PATCH 06/12] adding tests --- lib/matplotlib/tests/test_axes.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index dffbb2377a23..1a23710c7ef0 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3078,6 +3078,18 @@ def layers(n, m): fig, axs = plt.subplots(2, 2) + # Attempt to use an integer value for 'baseline' + try: + axs[0, 0].stackplot(range(100), d.T, baseline=5) + except ValueError as e: + print("Error when using an integer as baseline:", e) + + # Attempt to use a float value for 'baseline' + try: + axs[0, 1].stackplot(range(100), d.T, baseline=2.5) + except ValueError as e: + print("Error when using a float as baseline:", e) + axs[0, 0].stackplot(range(100), d.T, baseline='zero') axs[0, 1].stackplot(range(100), d.T, baseline='sym') axs[1, 0].stackplot(range(100), d.T, baseline='wiggle') From 2ac134403987afb73a2de239e2b6dac72980ff6d Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Wed, 22 Nov 2023 22:42:01 -0300 Subject: [PATCH 07/12] fixing tests --- lib/matplotlib/tests/test_axes.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 1a23710c7ef0..a9fcd73f2032 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3079,16 +3079,11 @@ def layers(n, m): fig, axs = plt.subplots(2, 2) # Attempt to use an integer value for 'baseline' - try: - axs[0, 0].stackplot(range(100), d.T, baseline=5) - except ValueError as e: - print("Error when using an integer as baseline:", e) + axs[0, 0].stackplot(range(100), d.T, baseline=5) # Attempt to use a float value for 'baseline' - try: - axs[0, 1].stackplot(range(100), d.T, baseline=2.5) - except ValueError as e: - print("Error when using a float as baseline:", e) + axs[0, 1].stackplot(range(100), d.T, baseline=2.5) + axs[0, 0].stackplot(range(100), d.T, baseline='zero') axs[0, 1].stackplot(range(100), d.T, baseline='sym') From 67df322064adb5d7f3823e439368eb1947c925b3 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:23:05 -0300 Subject: [PATCH 08/12] accepting datetime and timedelta --- lib/matplotlib/stackplot.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 4975373bd05b..12c01308786f 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -45,6 +45,9 @@ def stackplot(axes, x, *args, - ``float``: Scalar baseline. Useful for cases where 0 is not sensible. Any type that can be casted to float is accepted (int, float, bool and custom data objects) + - ``datetime64``: Calculates de difference between the date and + '1970-01-01' in seconds. + - ``timedelta64``: Converts the timedelta to seconds labels : list of str, optional A sequence of labels to assign to each data series. If unspecified, @@ -129,8 +132,18 @@ def stackplot(axes, x, *args, first_line = center - 0.5 * total stack += first_line + elif isinstance(baseline, np.datetime64): + first_date = np.datetime64('1970-01-01') + baseline = baseline - first_date + first_line = baseline / np.timedelta64(1, 's') + stack += first_line + + elif isinstance(baseline, np.timedelta64): + first_line = baseline / np.timedelta64(1, 's') + stack += first_line + else: - # Here we are 100% certain that baseline is not a string + # Here we are 100% certain that baseline is not a string and not date-time/timedelta first_line = float(baseline) # Color between x = 0 and the first array. From c3c770684d4d4261cb9a801f0464ad8e65017fbf Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:25:57 -0300 Subject: [PATCH 09/12] fixing linting --- lib/matplotlib/stackplot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 12c01308786f..a322a17fd051 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -32,7 +32,8 @@ def stackplot(axes, x, *args, stackplot(x, y) # where y has shape (M, N) stackplot(x, y1, y2, y3) # where y1, y2, y3, y4 have length N - baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle', float} + baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle', float, + datetime, timedelta} Method used to calculate the baseline: - ``'zero'``: Constant zero baseline, i.e. a simple stacked plot. @@ -143,7 +144,8 @@ def stackplot(axes, x, *args, stack += first_line else: - # Here we are 100% certain that baseline is not a string and not date-time/timedelta + # Here we are 100% certain that baseline is not a + #string and not date-time/timedelta first_line = float(baseline) # Color between x = 0 and the first array. From a4efe2292279d97939d57e4a71d93da1d735be75 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:29:18 -0300 Subject: [PATCH 10/12] fixing coment --- lib/matplotlib/stackplot.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index a322a17fd051..66c740dec869 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -144,8 +144,10 @@ def stackplot(axes, x, *args, stack += first_line else: - # Here we are 100% certain that baseline is not a - #string and not date-time/timedelta + """ + Here we are 100% certain that baseline is not a + string and not date-time/timedelta + """ first_line = float(baseline) # Color between x = 0 and the first array. From 197754959b2584f1e95a9840f1c316e991ad0705 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:31:12 -0300 Subject: [PATCH 11/12] fixing space lines in test --- lib/matplotlib/tests/test_axes.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index a9fcd73f2032..3dce8fbc9d12 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3083,14 +3083,11 @@ def layers(n, m): # Attempt to use a float value for 'baseline' axs[0, 1].stackplot(range(100), d.T, baseline=2.5) - - axs[0, 0].stackplot(range(100), d.T, baseline='zero') axs[0, 1].stackplot(range(100), d.T, baseline='sym') axs[1, 0].stackplot(range(100), d.T, baseline='wiggle') axs[1, 1].stackplot(range(100), d.T, baseline='weighted_wiggle') - @check_figures_equal() def test_stackplot_hatching(fig_ref, fig_test): x = np.linspace(0, 10, 10) From 460efa3d00e2b93638d1b3581205a057eb4d86c7 Mon Sep 17 00:00:00 2001 From: Eric Leao <86169515+EricRLeao1311@users.noreply.github.com> Date: Wed, 22 Nov 2023 23:32:21 -0300 Subject: [PATCH 12/12] adding space lines in tests --- lib/matplotlib/tests/test_axes.py | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/matplotlib/tests/test_axes.py b/lib/matplotlib/tests/test_axes.py index 3dce8fbc9d12..441dabdb80b3 100644 --- a/lib/matplotlib/tests/test_axes.py +++ b/lib/matplotlib/tests/test_axes.py @@ -3088,6 +3088,7 @@ def layers(n, m): axs[1, 0].stackplot(range(100), d.T, baseline='wiggle') axs[1, 1].stackplot(range(100), d.T, baseline='weighted_wiggle') + @check_figures_equal() def test_stackplot_hatching(fig_ref, fig_test): x = np.linspace(0, 10, 10)
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: