Is there any way to get a pointer to an AxesImage instance within a subplot? For example, in a general case such as:
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(10,10)
fig, ax = plt.subplots(1,1)
ax.imshow(data)
Getting back the AxesImage object via something like ax.get_image. At the moment I do this via:
ls = [type(x) for x in ax.get_children()]
img = ax.get_children()[ls.index(matplotlib.image.AxesImage)]
And was wondering if there is a less explicit way of doing it.
As pointed out by DavidG in the comments, there is a method to get a list of Images within an AxesSubpolot like so:
import matplotlib.pyplot as plt
import numpy as np
data = np.random.rand(10,10)
fig, ax = plt.subplots(1,1)
ax.imshow(data)
img = ax.get_images()[0] # only one image in this axes instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With