I have got a figure with with an axis object.
I would like to use ax.scatter to scatter something into the plot, which is no problem. On top I want to draw 2D array data into the same figure (using ax.imshow for example...):
import numpy as np
from matplotlib import pyplot as plt
vidRes = np.array([[-700, 700], [-500,500]])
dim = np.array([vidRes[0,1] - vidRes[0,0],vidRes[1,1] - vidRes[1,0]])
with plt.style.context('dark_background'):
fg = plt.figure()
fg.set_size_inches((10, 10*dim[1]/dim[0]))
ax = fg.add_subplot(111)
ax.set_aspect('equal')
ax.get_xaxis().set_visible(False)
ax.get_yaxis().set_visible(False)
ax.set_xlim(vidRes[0,0], vidRes[0,1])
ax.set_ylim(vidRes[1,0], vidRes[1,1])
random = np.random.random(size = (401, 401,),)
ax.imshow(random, cmap = 'hot')
The 2D array has 401x401 entries. Is there a straight forward way to move the imshow object to center it on a given pixel in my 1400x1000 pixel figure? Am I blind to not see it?
The image is drawn into the figure but it is always aligned with the lower left or upper left corner (depending on origin of ax.imshow) to the (0,0) coordinate at the center of my plot, I can't move it anywhere else.
question from:
https://stackoverflow.com/questions/66065229/plot-2d-array-data-into-figure-centered-at-specific-pixel 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…