Skip to content

Commit

Permalink
Plotfile removal and d.legend update (#4)
Browse files Browse the repository at this point in the history
* Typos and minor edits

* Plotfile removal and d.legend update
  • Loading branch information
chaedri authored Jan 19, 2022
1 parent f88168b commit 45a92e1
Showing 1 changed file with 36 additions and 4 deletions.
40 changes: 36 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,20 @@ <h3>Plot min/max values of summer temperature and precipitation</h3>
<code class="python">
# remember to use the full path to the file if necessary
import matplotlib.pyplot as plt
plt.plotfile("temperatures.txt", cols=(0,1,2), delimiter=',', subplots=False)
import numpy as np
import datetime as dt
from matplotlib.dates import DateFormatter

data = np.loadtxt("temperatures.txt", unpack=True, skiprows=1, delimiter=",", dtype=str)
dates = data[0,:]
x = [dt.datetime.strptime(d,'%Y-%m-%d %H:%M:%S').date() for d in dates]
min_array = data[1,:].astype(float)
max_array = data[2,:].astype(float)
plt.gca().xaxis.set_major_formatter(DateFormatter('%Y'))
plt.plot(x, max_array, label="max")
plt.plot(x, min_array, label="min")
plt.grid(linestyle="--")
plt.legend()
plt.show()
</code>
</pre>
Expand Down Expand Up @@ -624,8 +637,27 @@ <h3>Plot temperatures in Raleigh and Ashville</h3>
<pre>
<code class="python">
import matplotlib.pyplot as plt
plt.plotfile("raleigh.txt", cols=(0,2), delimiter=',', subplots=False)
plt.plotfile("asheville.txt", cols=(0,2), delimiter=',', subplots=False, newfig=False)
import numpy as np
import datetime as dt
from matplotlib.dates import DateFormatter

ral_data = np.loadtxt("raleigh.txt", unpack=True, skiprows=1, delimiter=",", dtype=str)
ash_data = np.loadtxt("asheville.txt", unpack=True, skiprows=1, delimiter=",", dtype=str)

ral_dates = ral_data[0,:]
ash_dates = ash_data[0,:]

ral_x = [dt.datetime.strptime(d,'%Y-%m-%d %H:%M:%S').date() for d in ral_dates]
ash_x = [dt.datetime.strptime(d,'%Y-%m-%d %H:%M:%S').date() for d in ash_dates]

ral_temp = ral_data[2,:].astype(float)
ash_temp = ash_data[2,:].astype(float)

plt.gca().xaxis.set_major_formatter(DateFormatter('%Y'))
plt.plot(ral_x, ral_temp, label="Raleigh")
plt.plot(ash_x, ash_temp, label="Asheville")
plt.grid(linestyle="--")
plt.legend()
plt.show()
</code>
</pre>
Expand Down Expand Up @@ -846,7 +878,7 @@ <h3>Space-time cube representation</h3>
<li>Add <tt>NagsHead_99_08</tt> 3D raster from toolbar (Add various raster map layers -> Add 3D raster map layer -> select <tt>NagsHead_99_08</tt>).</li>
<li>Right click on 3D raster -> Zoom to selected map.</li>
<li>Paste d.legend command into GUI Command console:
<pre><code class="neutral">d.legend -f rast3d=NagsHead_years at=5,50,7,10 use=1999,2000,2001,2002,2003,2004,2005,2006,2007,2008</code></pre>
<pre><code class="neutral">d.legend -f raster_3d=NagsHead_years at=5,50,7,10 use=1999,2000,2001,2002,2003,2004,2005,2006,2007,2008</code></pre>
</li>
<li>Set lower resolution to speed up 3D rendering:
<pre><code>g.region -p3 res3=3 tbres=1</code></pre></li>
Expand Down

0 comments on commit 45a92e1

Please sign in to comment.