Overwrite points from pcolormesh if they aren't contained in a polygon

Asked
Active3 hr before
Viewed126 times

4 Answers

pcolormesh
90%

A turtle’s shape is stored in its shape variable and can be set using the set command,,Example: you can change any turtle from it’s existing NetLogo color to a half transparent version of that color using:,You can also define new turtle, patch and link variables using the turtles-own, patches-own and links-own keywords, like this:,Turtles, links, and labels can all contain RGBA lists as their color variables, however, patches cannot have RGBA pcolors You can set the color of a turtle to be approximately half transparent pure red with the following code:

Example_snippet/controller/utility/_pcolormesh.js/ ask one-of turtles [ set color. . .
ask one - of turtles[set color green]
Step 2 continued with ask one-of patches [ sprout 1 . . .
ask one - of patches[sprout 1]
load more v
88%

Here is a possible fix, It requires that the projection doesn't change int he life of the pcolormesh

Example_snippet/controller/utility/_pcolormesh.js/ import numpy as np def _inter. . .
import numpy as np

def _interp_grid(X):
   # helper
for below
if np.shape(X)[1] > 1:
   dX = np.diff(X, axis = 1) / 2.
X = np.hstack((X[: , [0]] - dX[: , [0]],
   X[: ,: -1] + dX,
   X[: , [-1]] + dX[: , [-1]]))
return X

x = np.array([1, 2, 0])
y = np.array([1, 2])

X, Y = np.meshgrid(x, y)

_interp_grid(X)
load more v
72%

If X and/or Y are 1-D arrays or column vectors they will be expanded as needed into the appropriate 2-D arrays, making a rectangular grid,,C may be a masked array

Example_snippet/controller/utility/_pcolormesh.js/ pcolor([X, Y,] C, **kwargs) . . .
pcolor([X, Y, ] C, ** kwargs)
load more v
65%

Stack Overflow for Teams Where developers & technologists share private knowledge with coworkers ,Thanks for contributing an answer to Stack Overflow!,Making statements based on opinion; back them up with references or personal experience,, How do non-trinitarians explain Isaiah 43:11 taking into account its immediate context?

Example_snippet/controller/utility/_model.js/ import geopandas as gpd import. . .
import geopandas as gpd
import matplotlib.pyplot as plt
import numpy as np
import matplotlib as mpl
from shapely.geometry
import Point

# Load polygon
world = gpd.read_file(gpd.datasets.get_path("naturalearth_lowres"))
UK = world[world.iso_a3 == "GBR"]

# plot 1
#UK.boundary.plot()

# Simulate a spatial pattern
xlims = (-8, 3)
ylims = (49, 60)
resolution = 0.05 # 0.05

# slice()
y, x = np.mgrid[slice(ylims[0], ylims[1] + resolution, resolution),
   slice(xlims[0], xlims[1] + resolution, resolution)]
z = 0.5 * x + np.sin(x) ** 2 + np.cos(y)

# Target geometry,
for point inside / outside polygon operation
ukgeom = UK['geometry'].values[0]

def prep_z(Xs, Ys, Zs):
   # Xs, Ys: result of np.meshgrid(lon, lat)
# Zs: function of (Xs, Ys) to be manipulated;
here hard - coded as `new_z`
for ro, (arow, acol) in enumerate(zip(Xs, Ys)):
   # need 2 level loop to handle each grid point
for co, xiyi in enumerate(zip(arow, acol)):
   pnt1 = Point(xiyi)
if pnt1.within(ukgeom):
   new_z[ro][co] = 1 #0:white, 1:black with cm= 'binary'
else :
   new_z[ro][co] = 0
pass
pass
# Usage of the
function above: prep_z(x, y, z)
# Result: new_z is modified.
# New z
for locations in /outside-polygon operation
new_z = np.zeros(z.shape)
prep_z(x, y, z)

# create custom colormap to use later
new_binary = mpl.colors.ListedColormap(np.array([
   [1., 1., 1., 1.],
   [0., 0., 0., 0.]
]))
# 0: white, 1: transparent with cm = 'new_binary'
# do not use alpha option to get the intended result

# Plot 2
fig, ax = plt.subplots(figsize = (6, 10))
im = ax.pcolormesh(x, y, z, cmap = 'viridis', zorder = 1)

im2 = ax.pcolormesh(x, y, new_z, cmap = new_binary, zorder = 2) # do not use alpha to get transparent mask

   UK.boundary.plot(ax = ax, color = 'black', zorder = 10)
fig.colorbar(im, ax = ax, shrink = 0.5)

plt.show()