如何删除python-ggplot中的数字?

时间:2014-04-09 03:07:37

标签: python pandas python-ggplot

python ggplot真棒,但我遇到了内存问题。

import pandas as pd
from ggplot import *


data = pd.DataFrame({"date": [1, 2, 3],
                     "value": [10, 20, 30]})

for i in range(30):
    gg = ggplot(aes(x='date', y='value'), data=data) + geom_point(alpha=0.5)
    print(gg)
    f = "fig{}.png".format(i)
    ggsave(f, gg)

此代码显示RuntimeWarning(ggplot-0.4.7)。

/lib/python2.7/site-packages/matplotlib/pyplot.py:412: RuntimeWarning: More than 20 figures have been opened. Figures created through the pyplot interface (`matplotlib.pyplot.figure`) are retained until explicitly closed and may consume too much memory. (To control this warning, see the rcParam `figure.max_num_figures`).

如何删除旧图?

1 个答案:

答案 0 :(得分:2)

ggplot使用matplotlib的pyplot接口。您可以使用以下命令关闭所有现有的pyplot数据:

# Importing this library as plt is a convention, same
# importing numpy as np, or pandas as pd
import matplotlib.pyplot as plt
plt.close('all')

ggplot仍然处于发展的早期阶段,所以希望其中一些问题能够在接近稳定版本时得到平滑。