Как получить обработчик контура из matplotlib? - PullRequest
0 голосов
/ 18 февраля 2020

Мне было интересно, как получить обработчик контуров из осей в matplotlib. Из приведенных ниже кодов и выводов вы можете легко обнаружить, что im - это matplotlib.contour.QuadContourSet, но в ax.get_children() такого нет. Я знаю, что могу получить im, назначая операции, но иногда использование ax.get_children() может значительно облегчить жизнь, когда я просто хочу использовать im в другом месте один раз.

Коды

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()

Выход

(<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>])
...