Я пытаюсь пролистать серию гистограмм на одной фигуре. В конечном счете, у меня будет кнопка, которая позволит мне двигаться вперед или назад по всей серии. Но пока я не могу очистить текущую гистограмму, чтобы освободить место для следующей.
Мой основной подход заключается в следующем:
fig, ax = plt.subplots(1)
ax.hist(hist1)
fig.show() # This successfully displays my histogram
ax.clear()
fig.show() # The histogram is still present. Clearing was ineffective.
Как очистить оси, чтобы фигура была готова к следующей гистограмме?
Минимальный, полный и проверяемый пример:
me@home:~/Projects/kerasECOC$ python
Python 2.7.14 |Anaconda custom (64-bit)| (default, Dec 7 2017, 17:05:42)
[GCC 7.2.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib.pyplot as plt
>>> import numpy as np
>>> a = np.random.randn(100)
>>> fig, ax = plt.subplots(1)
>>> ax.hist(a)
(array([ 7., 4., 16., 11., 15., 16., 17., 8., 3., 3.]), array([-1.96828374, -1.54116206, -1.11404039, -0.68691871, -0.25979703,
0.16732464, 0.59444632, 1.02156799, 1.44868967, 1.87581134,
2.30293302]), <a list of 10 Patch objects>)
>>> fig.show()
>>> ax.clear()
>>> fig.show() #Figure is unchanged. I expected a blank fig as in ImportanceOfBeingErnest's example
>>> plt.__version__
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'module' object has no attribute '__version__'
>>> import matplotlib
>>> matplotlib.__version__
'2.2.2'
>>>