In the solutions to the Challenge at the end of Episode 7 there are two code snippets that need to be fixed:
The following snippet should be updated from:
plt.figure()
canopy_SJER.plot(robust=True, cmap="viridis")
plt.title("Canopy Height Model for San Joaquin Experimental Range, Z Units: Meters")
plt.savefig("fig/03-SJER-CHM-map-05.png")
canopy_SJER.rio.to_raster("./data/outputs/CHM_SJER.tif")
To create the fig directory before saving to it and use os.path.join to build the save path in an OS agnostic way:
plt.figure()
canopy_SJER.plot(robust=True, cmap="viridis")
plt.title("Canopy Height Model for San Joaquin Experimental Range, Z Units: Meters")
os.makedirs("fig", exist_ok=True)
plt.savefig(os.path.join("fig", "03-SJER-CHM-map-05.png"))
canopy_SJER.rio.to_raster("./data/outputs/CHM_SJER.tif")
The final code snippet throws a TypeError: 'Figure' object is not iterable error and also contains a misnamed variable. This code snippet:
fig, ax = plt.figure(figsize=(9,6))
canopy_height_HARV_xarr.plot.hist(ax = ax, bins=50, color = "green").
plt.figure(figsize=(9,6))
canopy_SJER.plot.hist(ax = ax, bins=50, color = "brown")
...should be updated to change the call to plt.figure(figsize=(9,6)) to plt.subplots(figsize=(9,6), correct the variable name on the second line from canopy_height_HARV_xarr to canopy_HARV, and remove the extraneous call to plt.figure(figsize=(9,6)):
fig, ax = plt.subplots(figsize=(9,6))
canopy_HARV.plot.hist(ax = ax, bins=50, color = "green")
canopy_SJER.plot.hist(ax = ax, bins=50, color = "brown")
In the solutions to the Challenge at the end of Episode 7 there are two code snippets that need to be fixed:
The following snippet should be updated from:
To create the
fig
directory before saving to it and useos.path.join
to build the save path in an OS agnostic way:The final code snippet throws a
TypeError: 'Figure' object is not iterable
error and also contains a misnamed variable. This code snippet:...should be updated to change the call to
plt.figure(figsize=(9,6))
toplt.subplots(figsize=(9,6)
, correct the variable name on the second line fromcanopy_height_HARV_xarr
tocanopy_HARV
, and remove the extraneous call toplt.figure(figsize=(9,6))
: