I am using matplotlib to display a matrix using imshow. I am using the following code to display the image
plt.figure(figsize=(12,10))
ax = plt.gca()
im = plt.imshow(a,cmap=plt.cm.Reds, aspect=1,extent = [0.1,3.2,2.3,3.2])
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(im,cax=cax)
plt.plot(0.5,2.3,color='yellow',marker="*")
Now I would like to add a square somewhere using coordinates like this:
plt.scatter(0.5,2.3,color='yellow',marker="s")
but it just doesnt show on the picture, what could cause this ?
CodePudding user response:
You have to move your additional plot before make_axes_locatable
because the current Axes
changes:
plt.figure(figsize=(12,10))
ax = plt.gca()
im = plt.imshow(a,cmap=plt.cm.Reds, aspect=1,extent = [0.1,3.2,2.3,3.2])
plt.plot(0.5,2.3,color='yellow',marker="*") # <- MOVE HERE
divider = make_axes_locatable(ax)
cax = divider.append_axes("right", size="5%", pad=0.05)
plt.colorbar(im,cax=cax)
Or use ax.plot
instead of plt.plot