From ca1e45cab76ce78cdec3011d3c450b4bc31d01f3 Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Wed, 14 Apr 2021 13:59:19 -0400 Subject: [PATCH 1/7] add basic example --- examples/tutorials/date_time_charts.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index 4f4c5014960..5d457e0b075 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -208,4 +208,18 @@ # # Explanation. -# Code +x = pd.date_range("2013-05-01", periods=20, freq="4D") +y = [4, 5, 6, 8, 9, 5, 8, 9, 4, 2, 7, 4, 4, 2, 5, 8, 9, 6, 3, 1] + +fig = pygmt.Figure() +fig.plot(projection="X15c/10c", + region=[datetime.datetime(2013, 4, 22), datetime.datetime(2013, 7, 30), 0, 10], + frame=["WS", "af"], + x=x, + y=y, + style="c0.4c", + pen="1p", + color="red" +) + +fig.show() From dd66ce96d50706b388d47d9a50cc039479c12da5 Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Thu, 15 Apr 2021 15:40:25 -0400 Subject: [PATCH 2/7] Elaborate on example with axis labeling --- examples/tutorials/date_time_charts.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index 5d457e0b075..f8604f1d54e 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -208,18 +208,19 @@ # # Explanation. -x = pd.date_range("2013-05-01", periods=20, freq="4D") -y = [4, 5, 6, 8, 9, 5, 8, 9, 4, 2, 7, 4, 4, 2, 5, 8, 9, 6, 3, 1] +x = pd.date_range("2013-05-02", periods=10, freq="2D") +y = [4, 5, 6, 8, 9, 5, 8, 9, 4, 2] fig = pygmt.Figure() -fig.plot(projection="X15c/10c", - region=[datetime.datetime(2013, 4, 22), datetime.datetime(2013, 7, 30), 0, 10], - frame=["WS", "af"], - x=x, - y=y, - style="c0.4c", - pen="1p", - color="red" -) +with pygmt.config(FORMAT_DATE_MAP="o"): + fig.plot(projection="X15c/10c", + region=[datetime.datetime(2013, 5, 1), datetime.datetime(2013, 5, 25), 0, 10], + frame=["WS", "sxa1Of1D", "pxa5d", "pya1+ucm", "sy+lLength"], + x=x, + y=y, + style="c0.4c", + pen="1p", + color="green3", + ) fig.show() From 98ae1c17644d4f0dc7dd6fe936c9a5bf11494234 Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Thu, 15 Apr 2021 16:10:41 -0400 Subject: [PATCH 3/7] Add axis labeling example description --- examples/tutorials/date_time_charts.py | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index f8604f1d54e..13514b6d474 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -206,7 +206,25 @@ # Setting Primary and Secondary Time Axes # ---------------------- # -# Explanation. +# This example focuses on labeling the axes and setting intervals +# at which the labels are expected to appear. All of these modification +# are added to the ``frame`` argument and each item in that list modifies +# a specific section of the plot. +# +# Starting off with ``WS``, adding this string means that only +# Western/Left **(W)** and Southern/Bottom **(S)** borders of +# the plot will be shown. For more information on this, please +# refer to TODO: Link to documentation page needed +# +# The other important item in the ``frame`` list is +# ``sxa1Of1D``. This string modifies the secondary +# labeling **(s)** of the x-axis **(x)**. Specifically, +# it sets the main annotation and major tick spacing interval +# to one month **(O)** (capital letter o, not zero). Additionally, +# it sets the minor tick spacing interval to 1 day **(D)**. +# The labeling of this axis is also modified using +# ``pygmt.config(FORMAT_DATE_MAP="o")`` to use the month's +# name instead of its number. x = pd.date_range("2013-05-02", periods=10, freq="2D") y = [4, 5, 6, 8, 9, 5, 8, 9, 4, 2] From aa9f7da6584a2157f7960f783d9868b76097c3fd Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Thu, 15 Apr 2021 16:45:28 -0400 Subject: [PATCH 4/7] Add second axes example --- examples/tutorials/date_time_charts.py | 27 +++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index 13514b6d474..a1cf9aad9f6 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -210,7 +210,7 @@ # at which the labels are expected to appear. All of these modification # are added to the ``frame`` argument and each item in that list modifies # a specific section of the plot. -# +# # Starting off with ``WS``, adding this string means that only # Western/Left **(W)** and Southern/Bottom **(S)** borders of # the plot will be shown. For more information on this, please @@ -242,3 +242,28 @@ ) fig.show() + +######################################################################################## +# The same concept shown above can be applied to smaller +# as well as larger intervals. In this example, +# data is plotted for different times throughout two days. +# Axes labels are also modified to repeat for specific +# intervals, and a secondary label is used to show +# what day of the week it is. + +x = pd.date_range("2021-04-15", periods=8, freq="6H") +y = [2, 5, 3, 1, 5, 7, 9, 6] + +fig = pygmt.Figure() +with pygmt.config(FORMAT_CLOCK_MAP="-hhAM"): + fig.plot(projection="X15c/10c", + region=[datetime.datetime(2021, 4, 14, 23, 0, 0), datetime.datetime(2021, 4, 17), 0, 10], + frame=["WS", "sxa1K", "pxa6H", "pya1+ukm/h", "sy+lSpeed"], + x=x, + y=y, + style="n0.4c", + pen="1p", + color="lightseagreen", + ) + +fig.show() From 40d36c9920aec50cc232641f7aa032a4c50dd106 Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Thu, 15 Apr 2021 23:43:12 -0400 Subject: [PATCH 5/7] Expand description, removed unused section --- examples/tutorials/date_time_charts.py | 31 +++++++++----------------- 1 file changed, 11 insertions(+), 20 deletions(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index a1cf9aad9f6..923dcc7b640 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -177,23 +177,6 @@ # Code -######################################################################################## -# Python built-in: `datetime.datetime` - -# the Python built-in datetime and date -x = [datetime.date(2018, 1, 1), datetime.datetime(2019, 6, 1, 20, 5, 45)] -y = [6.5, 4.5] -fig.plot(x, y, style="i0.4c", pen="1p", color="seagreen") - -fig.show() - -# Code - -######################################################################################## -# Python built-in: `datetime.date` - -# Code - ######################################################################################## # Passing Min/Max Time into `region` parameter using `pygmt.info` # ---------------------- @@ -247,9 +230,17 @@ # The same concept shown above can be applied to smaller # as well as larger intervals. In this example, # data is plotted for different times throughout two days. -# Axes labels are also modified to repeat for specific -# intervals, and a secondary label is used to show -# what day of the week it is. +# Primary x-axis labels are modified to repeat every 6 hours +# and secondary x-axis label repeats every day and shows +# the day of the week. +# +# Other notable mentions in this example is +# ``pygmt.config(FORMAT_CLOCK_MAP="-hhAM")`` +# which specifies the used format for time. +# In this case, leading zeros are removed +# using **(-)**, and only hours are displayed. +# Additionally, an AM/PM system is being used +# instead of a 24-hour system. x = pd.date_range("2021-04-15", periods=8, freq="6H") y = [2, 5, 3, 1, 5, 7, 9, 6] From 3fa6d3e3c2504932800297924f4567ed5776c605 Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Thu, 15 Apr 2021 23:49:37 -0400 Subject: [PATCH 6/7] resolve Todo --- examples/tutorials/date_time_charts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index 923dcc7b640..1992ff99c17 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -197,7 +197,7 @@ # Starting off with ``WS``, adding this string means that only # Western/Left **(W)** and Southern/Bottom **(S)** borders of # the plot will be shown. For more information on this, please -# refer to TODO: Link to documentation page needed +# refer to :docs:`pygmt.Frames`. # # The other important item in the ``frame`` list is # ``sxa1Of1D``. This string modifies the secondary From b441ce2967a34ef166beab044e7d7f065982c89e Mon Sep 17 00:00:00 2001 From: noorbuchi Date: Fri, 16 Apr 2021 00:26:17 -0400 Subject: [PATCH 7/7] Add generation using pygmt.info --- examples/tutorials/date_time_charts.py | 38 ++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/examples/tutorials/date_time_charts.py b/examples/tutorials/date_time_charts.py index 1992ff99c17..7ac9226af67 100644 --- a/examples/tutorials/date_time_charts.py +++ b/examples/tutorials/date_time_charts.py @@ -165,7 +165,7 @@ fig.show() ######################################################################################## -# Using ``xarray.DataArray`` +# Using :meth:`xarray.DataArray` # ------------------------------------- # xarray.DataArray @@ -178,12 +178,44 @@ # Code ######################################################################################## -# Passing Min/Max Time into `region` parameter using `pygmt.info` +# Generating Region Using :meth:`pygmt.info` # ---------------------- # # Explanation of supported parameters + bug at #597. -# Code +data = [['20200712',1000], + ['20200714',1235], + ['20200716',1336], + ['20200719',1176], + ['20200721',1573], + ['20200724',1893], + ['20200729',1634]] + +df = pd.DataFrame( + data,columns = ['Date','Score']) + +df['Date'] = pd.to_datetime( + df['Date'], + format='%Y%m%d') + +fig = pygmt.Figure() +region = pygmt.info( + table=df[["Date", "Score"]], + per_column=True, + spacing=(5000, 1200), +) + +fig.plot( + region=region, + projection="X15c/10c", + frame=['WSen', "afg"], + x=df.Date, + y=df.Score, + style="c0.4c", + pen="1p", + color="green3", +) +fig.show() ######################################################################################## # Setting Primary and Secondary Time Axes