Context
Suppose I have the following gradient matrix:
[[0. 0.5 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0.5 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0.25 0.5 0.75 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0.25 0.5 0.75 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0.33333333 0.66666667 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0.25 0.5 0.75 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0.25 0.5 0.75 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0. 0.25 0.5 0.75 1. 0. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0. 0.2 0.4 0.6 0.8 1. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.25 0.5 0.75 1. 0. 0. 0. 0. 0. 0. 0. ]
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.2 0.4 0.6 0.8 1. 0. 0. 0. 0. 0. 0. ]]
Which yields the following plot:
MWE
That image can be created with a patch that only displays the gradient that runs accross the matrix with:
import matplotlib.pyplot as plt
from matplotlib.patches import PathPatch
from matplotlib.path import Path
from scipy.ndimage import rotate
def generate_patch_plot():
"""Creates the geometry of the logo."""
E=(8.0, 17.32050807568877)
F=(10.0, 17.32050807568877)
G=(16.0, 0)
H=(20.0, 0.0)
fig = plt.figure()
ax = fig.add_subplot(111, aspect="equal")
square_patch = Path([(0, 0), (0, 20), (20, 20), (20, 0), (0, 0)])
square_path_patch = PathPatch(square_patch, facecolor="none")
ax.add_patch(square_path_patch)
gradient_matrix=[[0,0.6,0],[0,0.6,0],[0,0.6,0]]
plt.plot(E[0], E[1], "ro", label="E")
plt.plot(F[0], F[1], "yo", label="F")
plt.plot(G[0], G[1], "bo", label="G")
plt.plot(H[0], H[1], "co", label="H")
im = plt.imshow(
gradient_matrix, # Gradient matrix
interpolation="bilinear",
origin="lower", # Something
cmap=plt.cm.hsv,
extent=[0, 20, 0, 20],
# extent=extension_domain,
# clip_path=patch, # original.
clip_path=square_path_patch,
clip_on=True,
)
# im.set_clip_path(patch) # original.
im.set_clip_path(square_path_patch)
plt.show()
where E,F,G,H are the top left, top right, bottom left bottom right coordinates of the patch. The patch ensures only the gradient is visible inside the patch, and that the rest of the matrix is ignored outside the patch. However, when I look at the plot that is generated, the matrix is plotted from top left at y=0 to y=15.
Question
How could one shift this matrix to be displayed from x = 4 to -24, and from y = 7 to -27?

