From 03baf9cfe1ba93aa0290049dc2b794dce3eb0a87 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:04:57 -0700 Subject: [PATCH 1/8] Add XY_7_2 plot --- Plots/XY/xy_7_2_lg.py | 98 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 Plots/XY/xy_7_2_lg.py diff --git a/Plots/XY/xy_7_2_lg.py b/Plots/XY/xy_7_2_lg.py new file mode 100644 index 000000000..fa7001f0d --- /dev/null +++ b/Plots/XY/xy_7_2_lg.py @@ -0,0 +1,98 @@ +""" +xy_7_2_lg.py +=============== +An example of a double y plot: two separate line with their own unique axis. + +https://www.ncl.ucar.edu/Applications/Images/xy_7_2_lg.png + +""" + +############################################################################### +# Import modules + +import xarray as xr +import matplotlib.pyplot as plt + + +################################################################################ +# +# open data file and extract a slice of the data +# + +dset = xr.open_dataset("../../data/netcdf_files/TestData.xy3.nc") +ds = dset.isel(case=0, time=slice(0, 35)) + + +################################################################################ +# +# Create XY plot with two different Y axes +# + + +def nclize_axis(ax): + """ + Utility function to make plots look like NCL plots + """ + import matplotlib.ticker as tic + + ax.tick_params(labelsize="small") + ax.minorticks_on() + ax.xaxis.set_minor_locator(tic.AutoMinorLocator(n=3)) + ax.yaxis.set_minor_locator(tic.AutoMinorLocator(n=3)) + + # length and width are in points and may need to change depending on figure size etc. + ax.tick_params( + "both", + length=8, + width=1.5, + which="major", + bottom=True, + top=True, + left=True, + right=True, + ) + ax.tick_params( + "both", + length=5, + width=0.75, + which="minor", + bottom=True, + top=True, + left=True, + right=True, + ) + + +fig, ax1 = plt.subplots(figsize=(12, 12)) + +fontsize = 18 +labelsize = 20 +color = "blue" +linestyle = "-" +nclize_axis(ax1) +ax1.set_xlabel(ds.time.long_name) +ax1.set_ylabel(f"{ds.T.long_name} [solid]", fontsize=fontsize) +ax1.plot(ds.time, ds.T, color=color, linestyle=linestyle, linewidth=2.0) +ax1.set_xlim(xmin=1970, xmax=1973) +ax1.set_ylim(ymin=0.0, ymax=16.0) +ax1.set_yticks(np.arange(0, 16, 3)) + + +ax2 = ax1.twinx() +nclize_axis(ax2) + + +color = "red" +linestyle = "--" +# we already handled the x-label with ax1 +ax2.set_ylabel(f"{ds.P.long_name} [dash]", fontsize=fontsize) +ax2.plot(ds.time, ds.P, color=color, linestyle=linestyle, linewidth=2.0) +ax2.tick_params(axis="both", labelsize=labelsize) +ax2.set_ylim(ymin=1008.0, ymax=1024.0) +ax2.set_yticks(np.arange(1008, 1024, 3)) + + +plt.title("Curves Offset", fontsize=fontsize) + +fig.tight_layout() +plt.show() From de9e7fbf59a93d6326e70a4a9fdb367f7f8ae3ff Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:05:46 -0700 Subject: [PATCH 2/8] format with black --- Plots/XY/xy_7_2_lg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plots/XY/xy_7_2_lg.py b/Plots/XY/xy_7_2_lg.py index fa7001f0d..5747302c5 100644 --- a/Plots/XY/xy_7_2_lg.py +++ b/Plots/XY/xy_7_2_lg.py @@ -61,8 +61,8 @@ def nclize_axis(ax): left=True, right=True, ) - - + + fig, ax1 = plt.subplots(figsize=(12, 12)) fontsize = 18 From 7012f24814d94036a99089feff7afeb272242c2b Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:06:36 -0700 Subject: [PATCH 3/8] Update data sub-dir --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index a30b93c20..3fdbb1e01 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit a30b93c20b8dd1e016b8b24fe478aa767581a905 +Subproject commit 3fdbb1e0174ea571e38d181d07cb9dd68f2a5c6d From 26c4800aeb0b14c1f2ce371cc36774e705a002c5 Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:27:39 -0700 Subject: [PATCH 4/8] Update data submodule tracking to latest commit --- data | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data b/data index 3fdbb1e01..a30b93c20 160000 --- a/data +++ b/data @@ -1 +1 @@ -Subproject commit 3fdbb1e0174ea571e38d181d07cb9dd68f2a5c6d +Subproject commit a30b93c20b8dd1e016b8b24fe478aa767581a905 From b75b18f0855e0ea81dc5f69e766bd0ad0dd62d7c Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:32:46 -0700 Subject: [PATCH 5/8] Fix missing import --- Plots/XY/xy_7_2_lg.py | 1 + 1 file changed, 1 insertion(+) diff --git a/Plots/XY/xy_7_2_lg.py b/Plots/XY/xy_7_2_lg.py index 5747302c5..8a353c940 100644 --- a/Plots/XY/xy_7_2_lg.py +++ b/Plots/XY/xy_7_2_lg.py @@ -12,6 +12,7 @@ import xarray as xr import matplotlib.pyplot as plt +import numpy as np ################################################################################ From 9061c60d78ef8516b5d30e20b55d3a3dd330ebba Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:38:08 -0700 Subject: [PATCH 6/8] Fix tick_params --- Plots/XY/xy_7_2_lg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plots/XY/xy_7_2_lg.py b/Plots/XY/xy_7_2_lg.py index 8a353c940..c299974c3 100644 --- a/Plots/XY/xy_7_2_lg.py +++ b/Plots/XY/xy_7_2_lg.py @@ -10,10 +10,9 @@ ############################################################################### # Import modules -import xarray as xr import matplotlib.pyplot as plt import numpy as np - +import xarray as xr ################################################################################ # @@ -74,6 +73,7 @@ def nclize_axis(ax): ax1.set_xlabel(ds.time.long_name) ax1.set_ylabel(f"{ds.T.long_name} [solid]", fontsize=fontsize) ax1.plot(ds.time, ds.T, color=color, linestyle=linestyle, linewidth=2.0) +ax1.tick_params(axis="both", labelsize=labelsize) ax1.set_xlim(xmin=1970, xmax=1973) ax1.set_ylim(ymin=0.0, ymax=16.0) ax1.set_yticks(np.arange(0, 16, 3)) From 3c3db9115931838a3f0e058705906acf0669da1f Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Thu, 23 Jan 2020 12:50:01 -0700 Subject: [PATCH 7/8] Final changes --- Plots/XY/xy_7_2_lg.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Plots/XY/xy_7_2_lg.py b/Plots/XY/xy_7_2_lg.py index c299974c3..f509319ce 100644 --- a/Plots/XY/xy_7_2_lg.py +++ b/Plots/XY/xy_7_2_lg.py @@ -65,12 +65,12 @@ def nclize_axis(ax): fig, ax1 = plt.subplots(figsize=(12, 12)) -fontsize = 18 +fontsize = 24 labelsize = 20 color = "blue" linestyle = "-" nclize_axis(ax1) -ax1.set_xlabel(ds.time.long_name) +ax1.set_xlabel(ds.time.long_name, fontsize=fontsize) ax1.set_ylabel(f"{ds.T.long_name} [solid]", fontsize=fontsize) ax1.plot(ds.time, ds.T, color=color, linestyle=linestyle, linewidth=2.0) ax1.tick_params(axis="both", labelsize=labelsize) From 2d5cea44c82c5b918c91e9c3cf6e2d8871f70e6d Mon Sep 17 00:00:00 2001 From: Anderson Banihirwe Date: Fri, 24 Jan 2020 14:44:11 -0700 Subject: [PATCH 8/8] Fix missing data point issue --- Plots/XY/xy_7_2_lg.py | 51 +++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/Plots/XY/xy_7_2_lg.py b/Plots/XY/xy_7_2_lg.py index f509319ce..4f6107c82 100644 --- a/Plots/XY/xy_7_2_lg.py +++ b/Plots/XY/xy_7_2_lg.py @@ -3,30 +3,31 @@ =============== An example of a double y plot: two separate line with their own unique axis. -https://www.ncl.ucar.edu/Applications/Images/xy_7_2_lg.png +- Original NCL script: https://www.ncl.ucar.edu/Applications/Scripts/xy_7.ncl +- https://www.ncl.ucar.edu/Applications/Images/xy_7_2_lg.png """ ############################################################################### # Import modules +# =============== import matplotlib.pyplot as plt import numpy as np import xarray as xr +import geocat.datafiles ################################################################################ -# -# open data file and extract a slice of the data -# +# Open data file and extract a slice of the data +# =============================================== -dset = xr.open_dataset("../../data/netcdf_files/TestData.xy3.nc") -ds = dset.isel(case=0, time=slice(0, 35)) +dset = xr.open_dataset(geocat.datafiles.get("netcdf_files/TestData.xy3.nc")) +ds = dset.isel(case=0, time=slice(0, 36)) ################################################################################ -# # Create XY plot with two different Y axes -# +# ========================================= def nclize_axis(ax): @@ -37,7 +38,7 @@ def nclize_axis(ax): ax.tick_params(labelsize="small") ax.minorticks_on() - ax.xaxis.set_minor_locator(tic.AutoMinorLocator(n=3)) + ax.xaxis.set_minor_locator(tic.AutoMinorLocator(n=5)) ax.yaxis.set_minor_locator(tic.AutoMinorLocator(n=3)) # length and width are in points and may need to change depending on figure size etc. @@ -63,37 +64,31 @@ def nclize_axis(ax): ) -fig, ax1 = plt.subplots(figsize=(12, 12)) - -fontsize = 24 -labelsize = 20 -color = "blue" -linestyle = "-" +fig, ax1 = plt.subplots(figsize=(12, 8)) nclize_axis(ax1) -ax1.set_xlabel(ds.time.long_name, fontsize=fontsize) -ax1.set_ylabel(f"{ds.T.long_name} [solid]", fontsize=fontsize) -ax1.plot(ds.time, ds.T, color=color, linestyle=linestyle, linewidth=2.0) -ax1.tick_params(axis="both", labelsize=labelsize) +ax1.set_xlabel(ds.time.long_name, fontsize=24) +ax1.set_ylabel(f"{ds.T.long_name} [solid]", fontsize=24) +ax1.plot(ds.time, ds.T, color="blue", linestyle="-", linewidth=2.0) +ax1.tick_params(axis="both", labelsize=20) ax1.set_xlim(xmin=1970, xmax=1973) ax1.set_ylim(ymin=0.0, ymax=16.0) -ax1.set_yticks(np.arange(0, 16, 3)) +ax1.set_yticks(np.arange(0, 17, 3)) ax2 = ax1.twinx() nclize_axis(ax2) -color = "red" -linestyle = "--" # we already handled the x-label with ax1 -ax2.set_ylabel(f"{ds.P.long_name} [dash]", fontsize=fontsize) -ax2.plot(ds.time, ds.P, color=color, linestyle=linestyle, linewidth=2.0) -ax2.tick_params(axis="both", labelsize=labelsize) -ax2.set_ylim(ymin=1008.0, ymax=1024.0) -ax2.set_yticks(np.arange(1008, 1024, 3)) + +ax2.set_ylabel(f"{ds.P.long_name} [dash]", fontsize=24) +ax2.plot(ds.time, ds.P, color="red", linestyle="--", linewidth=2.0, dashes=[6.5, 3.7]) +ax2.tick_params(axis="both", labelsize=20) +ax2.set_ylim(ymin=1008, ymax=1024.0) +ax2.set_yticks(np.arange(1008, 1025, 3)) -plt.title("Curves Offset", fontsize=fontsize) +plt.title("Curves Offset", fontsize=24, fontweight="bold", y=1.05) fig.tight_layout() plt.show()