Python matplotlib.animation [Errno 13]权限被拒绝

时间:2016-02-11 18:44:12

标签: python matplotlib ffmpeg

我正在尝试创建一个简单的动画直方图,并在mac上使用matplotlib和ffmpeg将其保存为.mp4。我已经安装了ffMpeg,指定了ffmpeg路径,现在我在写入桌面文件夹时收到权限被拒绝错误。我尝试运行sudo仍然得到相同的错误。非常感谢帮助,谢谢!

以下是代码:

df = pd.read_csv('.../data.csv')

df = df.dropna()
#Get list of weeks
weeks = df.ot_date.unique()
fig, ax = plt.subplots()

data = df.intervals_filled[df['ot_date'].isin([weeks[0]])]
n, bins = np.histogram( data , 20)

# get the corners of the rectangles for the histogram
left = np.array(bins[:-1])
right = np.array(bins[1:])
bottom = np.zeros(len(left))
top = bottom + n
nrects = len(left)

# here comes the tricky part -- we have to set up the vertex and path
# codes arrays using moveto, lineto and closepoly

# for each rect: 1 for the MOVETO, 3 for the LINETO, 1 for the
# CLOSEPOLY; the vert for the closepoly is ignored but we still need
# it to keep the codes aligned with the vertices
nverts = nrects*(1 + 3 + 1)
verts = np.zeros((nverts, 2))
codes = np.ones(nverts, int) * path.Path.LINETO
codes[0::5] = path.Path.MOVETO
codes[4::5] = path.Path.CLOSEPOLY
verts[0::5, 0] = left
verts[0::5, 1] = bottom
verts[1::5, 0] = left
verts[1::5, 1] = top
verts[2::5, 0] = right
verts[2::5, 1] = top
verts[3::5, 0] = right
verts[3::5, 1] = bottom

barpath = path.Path(verts, codes)
patch = patches.PathPatch(
    barpath, facecolor='green', edgecolor='yellow', alpha=0.5)
ax.add_patch(patch)

ax.set_xlim(left[0], right[-1])
ax.set_ylim(bottom.min(), top.max()+40)
ax.set_xlabel('Number of intervals/week')
ax.set_ylabel('Count of CSAs')
plt.rcParams['animation.ffmpeg_path'] = '/usr/local/Cellar/ffmpeg'
FFwriter = animation.FFMpegWriter()

def animate(i):
    print i
    # simulate new data coming in
    data = df.intervals_filled[df['ot_date'].isin([weeks[i-1]])]
    n, bins = np.histogram(data, 20)
    yearweek = str(weeks[i-1])
    year = yearweek[0:4]
    week = yearweek[4:]
    title = 'Week %(wk)s of %(yr)s' %{'wk': week, 'yr': year}
    ax.set_title(title)
    top = bottom + n
    verts[1::5, 1] = top
    verts[2::5, 1] = top
    return [patch, ]

ani = animation.FuncAnimation(fig, animate, 53,interval=1000, repeat=False)
ani.save('/Users/.../Desktop/1b.mp4', writer = FFwriter)
plt.show()

这是追溯:

Traceback (most recent call last):
  File "/Users/Fishman1049/Desktop/reserves_histogram_timeline/python/1b_text.py", line 109, in <module>
    ani.save('/Users/Fishman1049/Desktop/1b', writer = FFwriter)
  File "/Users/Fishman1049/anaconda/lib/python2.7/site-packages/matplotlib/animation.py", line 761, in save
    with writer.saving(self._fig, filename, dpi):
  File "/Users/Fishman1049/anaconda/lib/python2.7/contextlib.py", line 17, in __enter__
    return self.gen.next()
  File "/Users/Fishman1049/anaconda/lib/python2.7/site-packages/matplotlib/animation.py", line 186, in saving
    self.setup(*args)
  File "/Users/Fishman1049/anaconda/lib/python2.7/site-packages/matplotlib/animation.py", line 176, in setup
    self._run()
  File "/Users/Fishman1049/anaconda/lib/python2.7/site-packages/matplotlib/animation.py", line 204, in _run
    creationflags=subprocess_creation_flags)
  File "/Users/Fishman1049/anaconda/lib/python2.7/subprocess.py", line 710, in __init__
    errread, errwrite)
  File "/Users/Fishman1049/anaconda/lib/python2.7/subprocess.py", line 1335, in _execute_child
    raise child_exception
OSError: [Errno 13] Permission denied

我正在运行matplotlib 1.5.1版,今天刚刚使用自制程序,spyder 2.3.8,python 2.7和OS X 10.10.5安装了FFmpeg。谢谢!。

0 个答案:

没有答案