From 8eb62891d5ea3f2cc589702ec97f5840edccee75 Mon Sep 17 00:00:00 2001 From: Alexandra Khoo <43926254+thedatacurious@users.noreply.github.com> Date: Mon, 24 Mar 2025 00:08:22 +0000 Subject: [PATCH 1/7] Update lib/matplotlib/stackplot.py --- lib/matplotlib/stackplot.py | 51 ++++++++++++++++++++++++++++++++----- 1 file changed, 45 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 43da57c25da5..92c25204e067 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -23,14 +23,53 @@ def stackplot(axes, x, *args, Parameters ---------- - x : (N,) array-like + x : array-like - y : (M, N) array-like - The data is assumed to be unstacked. Each of the following - calls is legal:: + y : multiple array-like, 2D array-like or pandas.DataFrame - stackplot(x, y) # where y has shape (M, N) - stackplot(x, y1, y2, y3) # where y1, y2, y3, y4 have length N + - multiple array-like: the data is unstacked + + .. code-block:: none + + # year_1, year_2, year_3 + y1 = [value_1_A, value_2_A, value_3_A] # category_A + y2 = [value_1_B, value_2_B, value_3_B] # category_B + y3 = [value_1_C, value_2_C, value_3_C] # category_C + + x = [*range(3)] + + Example call: + + .. code-block:: python + + stackplot(x, y1, y2, y3) + + - 2D array-like: Each row represents a category, each column represents an x-axis dimension associated with the categories. A list of 1D array-like can also be passed; each list item must have the same length + + Example call: + + .. code-block:: python + + y = [y1, y2, y3] + x = [*range(3)] + + stackplot(x, y) + + - a `pandas.DataFrame`: The index is used for the categories, each column represents an x-axis dimension associated with the categories. + + Example call: + + .. code-block:: python + + y = pd.DataFrame( + np.random.random((3, 3)), + index=["category_A", "category_B", "category_C"], + columns=[*range(3)] + ) + + x = df.columns + + stackplot(x, y) baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle'} Method used to calculate the baseline: From 5d722a9aa49c66544d8db3e01b1607a8e22145ca Mon Sep 17 00:00:00 2001 From: Alexandra Khoo <43926254+thedatacurious@users.noreply.github.com> Date: Tue, 1 Apr 2025 18:06:38 +0000 Subject: [PATCH 2/7] Simplify update to lib/matplotlib/stackplot.py --- lib/matplotlib/stackplot.py | 52 +++++++------------------------------ 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 92c25204e067..4fb181afb14e 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -23,53 +23,21 @@ def stackplot(axes, x, *args, Parameters ---------- - x : array-like + x : (N, ) array-like - y : multiple array-like, 2D array-like or pandas.DataFrame - - - multiple array-like: the data is unstacked + y : (M, N) array-like or pandas.DataFrame + The data is assumed to be unstacked. Each of the following + calls is legal:: - .. code-block:: none + stackplot(x, y) # where y = [y1, y2, y3, y4] + # or y = pd.DataFrame(np.random.random((4, 3)), + # index=["category_A", "category_B", "category_C", "category_D"], + # columns=["period_1", "period_2", "period_3"]) - # year_1, year_2, year_3 - y1 = [value_1_A, value_2_A, value_3_A] # category_A - y2 = [value_1_B, value_2_B, value_3_B] # category_B - y3 = [value_1_C, value_2_C, value_3_C] # category_C + stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N - x = [*range(3)] - - Example call: - - .. code-block:: python - - stackplot(x, y1, y2, y3) - - - 2D array-like: Each row represents a category, each column represents an x-axis dimension associated with the categories. A list of 1D array-like can also be passed; each list item must have the same length - - Example call: - - .. code-block:: python - - y = [y1, y2, y3] - x = [*range(3)] - - stackplot(x, y) - - - a `pandas.DataFrame`: The index is used for the categories, each column represents an x-axis dimension associated with the categories. - - Example call: - - .. code-block:: python - - y = pd.DataFrame( - np.random.random((3, 3)), - index=["category_A", "category_B", "category_C"], - columns=[*range(3)] - ) - - x = df.columns + - stackplot(x, y) baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle'} Method used to calculate the baseline: From f5392c6265cfffe5cece79cb5d68b84fff0d4c2a Mon Sep 17 00:00:00 2001 From: Alexandra Khoo <43926254+thedatacurious@users.noreply.github.com> Date: Thu, 3 Apr 2025 23:54:38 +0000 Subject: [PATCH 3/7] Rephrase minimal example for clarity --- lib/matplotlib/stackplot.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 4fb181afb14e..318d09a282af 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -25,14 +25,11 @@ def stackplot(axes, x, *args, ---------- x : (N, ) array-like - y : (M, N) array-like or pandas.DataFrame - The data is assumed to be unstacked. Each of the following + y : (M, N) array-like + The data can be either stacked or unstacked. Each of the following calls is legal:: - stackplot(x, y) # where y = [y1, y2, y3, y4] - # or y = pd.DataFrame(np.random.random((4, 3)), - # index=["category_A", "category_B", "category_C", "category_D"], - # columns=["period_1", "period_2", "period_3"]) + stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N From c58b12486f9062184a7fa657383d86cedb874f2b Mon Sep 17 00:00:00 2001 From: Alexandra Khoo <43926254+thedatacurious@users.noreply.github.com> Date: Fri, 4 Apr 2025 18:46:39 -0500 Subject: [PATCH 4/7] Update lib/matplotlib/stackplot.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- lib/matplotlib/stackplot.py | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 318d09a282af..561dead0f6ab 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -30,7 +30,6 @@ def stackplot(axes, x, *args, calls is legal:: stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] - stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N From 5aa620cfe770861f1a5b59ca44ecdced80153ff2 Mon Sep 17 00:00:00 2001 From: Alexandra Khoo <43926254+thedatacurious@users.noreply.github.com> Date: Sat, 5 Apr 2025 17:58:22 +0000 Subject: [PATCH 5/7] Remove trailing whitespaces --- lib/matplotlib/stackplot.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 561dead0f6ab..5c624c892132 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -28,11 +28,8 @@ def stackplot(axes, x, *args, y : (M, N) array-like The data can be either stacked or unstacked. Each of the following calls is legal:: - - stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] + stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N - - baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle'} From 3dbd98b0fcedddbfe7da128400322e5a53a4aa1c Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 7 Apr 2025 00:17:43 +0200 Subject: [PATCH 6/7] Apply suggestions from code review --- 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 5c624c892132..8b2a3dd9d890 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -23,13 +23,13 @@ def stackplot(axes, x, *args, Parameters ---------- - x : (N, ) array-like + x : (N,) array-like y : (M, N) array-like The data can be either stacked or unstacked. Each of the following calls is legal:: - stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] - stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N + stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] + stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle'} From 6d71c60aff21fdd7fe942fb61365e702ba17a622 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 7 Apr 2025 00:18:34 +0200 Subject: [PATCH 7/7] Update lib/matplotlib/stackplot.py --- lib/matplotlib/stackplot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/matplotlib/stackplot.py b/lib/matplotlib/stackplot.py index 8b2a3dd9d890..bd11558b0da9 100644 --- a/lib/matplotlib/stackplot.py +++ b/lib/matplotlib/stackplot.py @@ -28,10 +28,10 @@ def stackplot(axes, x, *args, y : (M, N) array-like The data can be either stacked or unstacked. Each of the following calls is legal:: + stackplot(x, y) # where y has shape (M, N) e.g. y = [y1, y2, y3, y4] stackplot(x, y1, y2, y3, y4) # where y1, y2, y3, y4 have length N - baseline : {'zero', 'sym', 'wiggle', 'weighted_wiggle'} Method used to calculate the baseline: