Skip to content

Commit

Permalink
Correcting plots
Browse files Browse the repository at this point in the history
With imshow, use resample=False and interpolation="nearest".
  • Loading branch information
ghislainv committed Jun 1, 2024
1 parent 17e5121 commit 2082bd9
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion forestatrisk/plot/niceplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def nice_plot_prob(
fig = nice_plot_prob(
"output/prob.tif",
maxpixels=1e8,
borders="data/ctry_PROJ.shp",
borders="data/ctry_PROJ.gpkg",
linewidth=0.2,
legend=True,
figsize=(5, 4),
Expand Down
39 changes: 26 additions & 13 deletions forestatrisk/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,8 @@ def fcc(
ax1.set_frame_on(False)
ax1.set_xticks([])
ax1.set_yticks([])
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
if borders is not None:
plot_layer(borders, symbol="k-", **kwargs)
plt.axis("off")
Expand All @@ -313,7 +314,8 @@ def fcc(
)
ax1.add_patch(z)
ax2 = plt.subplot(222)
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
plt.xlim(zoom[0], zoom[1])
plt.ylim(zoom[2], zoom[3])
ax2.set_xticks([])
Expand Down Expand Up @@ -421,7 +423,8 @@ def fcc12345(
ax1.set_frame_on(False)
ax1.set_xticks([])
ax1.set_yticks([])
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
if borders is not None:
plot_layer(borders, symbol="k-", **kwargs)
plt.axis("off")
Expand All @@ -431,7 +434,8 @@ def fcc12345(
)
ax1.add_patch(z)
ax2 = plt.subplot(222)
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
plt.xlim(zoom[0], zoom[1])
plt.ylim(zoom[2], zoom[3])
ax2.set_xticks([])
Expand Down Expand Up @@ -533,7 +537,8 @@ def fcc123(
ax1.set_frame_on(False)
ax1.set_xticks([])
ax1.set_yticks([])
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
if borders is not None:
plot_layer(borders, symbol="k-", **kwargs)
plt.axis("off")
Expand All @@ -543,7 +548,8 @@ def fcc123(
)
ax1.add_patch(z)
ax2 = plt.subplot(222)
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
plt.xlim(zoom[0], zoom[1])
plt.ylim(zoom[2], zoom[3])
ax2.set_xticks([])
Expand Down Expand Up @@ -645,7 +651,8 @@ def forest(
ax1.set_frame_on(False)
ax1.set_xticks([])
ax1.set_yticks([])
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
if borders is not None:
plot_layer(borders, symbol="k-", **kwargs)
plt.axis("off")
Expand All @@ -655,7 +662,8 @@ def forest(
)
ax1.add_patch(z)
ax2 = plt.subplot(222)
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
plt.xlim(zoom[0], zoom[1])
plt.ylim(zoom[2], zoom[3])
ax2.set_xticks([])
Expand Down Expand Up @@ -759,14 +767,16 @@ def prob(
fig = plt.figure(figsize=figsize, dpi=dpi)
plt.subplot(111)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
vmin=0.01, vmax=65535, resample=False)
vmin=0.01, vmax=65535,
resample=False, interpolation="nearest")
if borders is not None:
plot_layer(borders, symbol="k-", **kwargs)

# Legend
if legend is True:
t = np.linspace(1, 65535, 5, endpoint=True)
cbar = plt.colorbar(ticks=t, orientation="vertical", shrink=0.5, aspect=20)
cbar = plt.colorbar(ticks=t, orientation="vertical",
shrink=0.5, aspect=20)
vl = np.linspace(0, 1, 5, endpoint=True)
cbar.ax.set_yticklabels(vl)

Expand Down Expand Up @@ -853,7 +863,8 @@ def obs(
ax1.set_yticks([])
plt.axis("off")
# Raster
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
# Points
f = name_forest_var
x_defor = sample[sample[f] == 0]["X"]
Expand Down Expand Up @@ -951,7 +962,8 @@ def differences(
ax1.set_frame_on(False)
ax1.set_xticks([])
ax1.set_yticks([])
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
if borders is not None:
plot_layer(borders, symbol="k-", **kwargs)
plt.axis("off")
Expand All @@ -961,7 +973,8 @@ def differences(
)
ax1.add_patch(z)
ax2 = plt.subplot(222)
plt.imshow(ov_arr, cmap=color_map, extent=extent, resample=False)
plt.imshow(ov_arr, cmap=color_map, extent=extent,
resample=False, interpolation="nearest")
plt.xlim(zoom[0], zoom[1])
plt.ylim(zoom[2], zoom[3])
ax2.set_xticks([])
Expand Down

0 comments on commit 2082bd9

Please sign in to comment.