0

I was wondering how to get the contourf handler from an axes within matplotlib. From the codes and outputs below you can easily find that im is matplotlib.contour.QuadContourSet but no such kind of thing in ax.get_children(). I know I can obtain im by assigning operations but sometimes using ax.get_children() can make life much easier when I just want to use im in another place once.

Codes

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = plt.axes()
im = ax.contourf(np.random.random((10,10)))
im, ax.get_children()

Output

(<matplotlib.contour.QuadContourSet at 0x2abd4a3243c8>,
 [<matplotlib.collections.PathCollection at 0x2abd4a35b080>,
  <matplotlib.collections.PathCollection at 0x2abd4a35b4e0>,
  <matplotlib.collections.PathCollection at 0x2abd4a35ba58>,
  <matplotlib.collections.PathCollection at 0x2abd4a35be48>,
  <matplotlib.collections.PathCollection at 0x2abd4a365240>,
  <matplotlib.collections.PathCollection at 0x2abd4a365710>,
  <matplotlib.collections.PathCollection at 0x2abd4a365c18>,
  <matplotlib.spines.Spine at 0x2abd4a282a90>,
  <matplotlib.spines.Spine at 0x2abd4a282b38>,
  <matplotlib.spines.Spine at 0x2abd4a2f7320>,
  <matplotlib.spines.Spine at 0x2abd4a294d68>,
  <matplotlib.axis.XAxis at 0x2abd4a29a4a8>,
  <matplotlib.axis.YAxis at 0x2abd4a317748>,
  Text(0.5, 1.0, ''),
  Text(0.0, 1.0, ''),
  Text(1.0, 1.0, ''),
  <matplotlib.patches.Rectangle at 0x2abd4a33ca58>])
Fei Yao
  • 1,502
  • 10
  • 10

0 Answers0