【发布时间】:2015-12-03 14:40:47
【问题描述】:
我的代码(大致)是这样的:
更新:我已经用一些反映我的一般问题的实际模型代码重做了这个。此外,意识到颜色条的创建是在实际循环中,否则没有什么可以映射到的。很抱歉之前的代码,在工作日结束时绝望地输入它:)。
import numpy
import matplotlib as mplot
import matplotlib.pyplot as plt
import os
#make some mock data
x = np.linspace(1,2, 100)
X, Y = np.meshgrid(x, x)
Z = plt.mlab.bivariate_normal(X,Y,1,1,0,0)
fig = plt.figure()
ax = plt.axes()
'''
Do some figure-related stuff that take up a lot of time,
I want to avoid having to do them in the loop over and over again.
They hinge on the presence of fig so I can't make
new figure to save each time or something, I'd have to do
them all over again.
'''
for i in range(1,1000):
plotted = plt.plot(X,Y,Z)
cbar = plt.colorbar(ax=ax, orientation = 'horizontal')
plt.savefig(os.path.expanduser(os.path.join('~/', str(i))))
plt.draw()
mplot.figure.Figure.delaxes(fig, fig.axes[1]) #deletes but whitespace remains
'''
Here I need something to remove the colorbar otherwise
I end up with +1 colorbar on my plot at every iteration.
I've tried various things to remove it BUT it keeps adding whitespace instead
so doesn't actually fix anything.
'''
以前有没有人遇到过这个问题并设法解决它?希望这已经足够了 对于这个问题的想法,如果需要,我可以发布更多代码,但我认为如果我只是给出一个概述示例,那就不会那么混乱了。
谢谢。
【问题讨论】:
标签: python matplotlib