From 44d46ed3883c6d4c1700ca560db6094d49db8ffc Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 4 May 2020 11:04:10 -0700 Subject: [PATCH 1/2] DOC: add offset axes to secondary_axes --- .../secondary_axis.py | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/examples/subplots_axes_and_figures/secondary_axis.py b/examples/subplots_axes_and_figures/secondary_axis.py index 76f429f401fd..76dbf3ffa1e3 100644 --- a/examples/subplots_axes_and_figures/secondary_axis.py +++ b/examples/subplots_axes_and_figures/secondary_axis.py @@ -106,12 +106,13 @@ def inverse(x): ########################################################################### # A final example translates np.datetime64 to yearday on the x axis and -# from Celsius to Fahrenheit on the y axis: - +# from Celsius to Fahrenheit on the y axis. Note the addition of a +# third y axis, and that it can be placed using a float for the +# location argument dates = [datetime.datetime(2018, 1, 1) + datetime.timedelta(hours=k * 6) for k in range(240)] -temperature = np.random.randn(len(dates)) +temperature = np.random.randn(len(dates)) * 4 + 6.7 fig, ax = plt.subplots(constrained_layout=True) ax.plot(dates, temperature) @@ -147,6 +148,21 @@ def fahrenheit_to_celsius(x): 'right', functions=(celsius_to_fahrenheit, fahrenheit_to_celsius)) secax_y.set_ylabel(r'$T\ [^oF]$') + +def celsius_to_anomaly(x): + return (x - np.mean(temperature)) + + +def anomaly_to_celsius(x): + return (x + np.mean(temperature)) + + +# document use of a float for the position: +secax_y2 = ax.secondary_yaxis( + 1.2, functions=(celsius_to_anomaly, anomaly_to_celsius)) +secax_y2.set_ylabel(r'$T - \overline{T}\ [^oC]$') + + plt.show() ############################################################################# From 392e3dad234ff8f06b7923340d433be87b62363d Mon Sep 17 00:00:00 2001 From: Jody Klymak Date: Mon, 4 May 2020 13:51:13 -0700 Subject: [PATCH 2/2] Update examples/subplots_axes_and_figures/secondary_axis.py Co-authored-by: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> --- examples/subplots_axes_and_figures/secondary_axis.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/subplots_axes_and_figures/secondary_axis.py b/examples/subplots_axes_and_figures/secondary_axis.py index 76dbf3ffa1e3..c05459b9d94d 100644 --- a/examples/subplots_axes_and_figures/secondary_axis.py +++ b/examples/subplots_axes_and_figures/secondary_axis.py @@ -157,7 +157,7 @@ def anomaly_to_celsius(x): return (x + np.mean(temperature)) -# document use of a float for the position: +# use of a float for the position: secax_y2 = ax.secondary_yaxis( 1.2, functions=(celsius_to_anomaly, anomaly_to_celsius)) secax_y2.set_ylabel(r'$T - \overline{T}\ [^oC]$')