我的以下代码是:
import matplotlib
matplotlib.use('Agg') #necessario para salvar figura no crontab
import os
import numpy as np
import matplotlib.pylab as plt
from pandas import Series, DataFrame
import pandas as pd
import datetime as dt
from datetime import datetime
from pylab import *
import matplotlib.dates as mdates
pathname = 'C:\\Users\\leo_v\\Desktop\\Nova_pasta\\leo_170818\lioc\\'
pathnamep = 'C:\\Users\\leo_v\\Desktop\\Nova_pasta\\leo_170818\\avalia\\'
prevs = np.sort(os.listdir(pathnamep))
rgp1 = pd.read_csv(pathnamep + prevs[-3] + '/PNBOIA_riogrande.txt',sep='\s*',
names=['ano','mes','dia','hora','minu','hs','tp','dp','spr'])
flp1 = pd.read_csv(pathnamep + prevs[-3] + '/PNBOIA_floripa.txt',sep='\s*',
names=['ano','mes','dia','hora','minu','hs','tp','dp','spr'])
sap1 = pd.read_csv(pathnamep + prevs[-3] + '/PNBOIA_santos.txt',sep='\s*',
names=['ano','mes','dia','hora','minu','hs','tp','dp','spr'])
rjp1 = pd.read_csv(pathnamep + prevs[-3] + '/PNBOIA_SIODOC.txt',sep='\s*',
names=['ano','mes','dia','hora','minu','hs','tp','dp','spr'])
vip1 = pd.read_csv(pathnamep + prevs[-3] + '/PNBOIA_vitoria.txt',sep='\s*',
names=['ano','mes','dia','hora','minu','hs','tp','dp','spr'])
rgp1['data'] = pd.to_datetime(rgp1.ano.astype(str) + '/' + rgp1.mes.astype(str) + '/' + rgp1.dia.astype(str) + '-' + rgp1.hora.astype(str) ,format="%Y/%m/%d-%H")
flp1['data'] = pd.to_datetime(flp1.ano.astype(str) + '/' + flp1.mes.astype(str) + '/' + flp1.dia.astype(str) + '-' + flp1.hora.astype(str) ,format="%Y/%m/%d-%H")
sap1['data'] = pd.to_datetime(sap1.ano.astype(str) + '/' + sap1.mes.astype(str) + '/' + sap1.dia.astype(str) + '-' + sap1.hora.astype(str) ,format="%Y/%m/%d-%H")
rjp1['data'] = pd.to_datetime(rjp1.ano.astype(str) + '/' + rjp1.mes.astype(str) + '/' + rjp1.dia.astype(str) + '-' + rjp1.hora.astype(str) ,format="%Y/%m/%d-%H")
vip1['data'] = pd.to_datetime(vip1.ano.astype(str) + '/' + vip1.mes.astype(str) + '/' + vip1.dia.astype(str) + '-' + vip1.hora.astype(str) ,format="%Y/%m/%d-%H")
rgp1 = rgp1.set_index('data')
flp1 = flp1.set_index('data')
sap1 = sap1.set_index('data')
rjp1 = rjp1.set_index('data')
#izp1 = izp1.set_index('data')
vip1 = vip1.set_index('data')
rgp1 = rgp1.ix[:,['hs','tp','dp','spr']]
flp1 = flp1.ix[:,['hs','tp','dp','spr']]
sap1 = sap1.ix[:,['hs','tp','dp','spr']]
rjp1 = rjp1.ix[:,['hs','tp','dp','spr']]
#izp1 = izp1.ix[:,['hs','tp','dp']]
vip1 = vip1.ix[:,['hs','tp','dp','spr']]
hoje = dt.datetime.strftime(dt.datetime.today(),'%Y%m%d')
tj = 15 * 24
plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
params = {'text.usetex' : True,
'font.size' : 11,
'font.family' : 'lmodern',
'text.latex.unicode': True,
}
plt.rcParams.update(params)
plt.rcParams['text.latex.preamble']=[r"\usepackage{lmodern}"]
params = {'text.usetex' : True,
'font.size' : 14,
'font.family' : 'lmodern',
'text.latex.unicode': True,
}
plt.rcParams.update(params)
u=1*np.sin(np.radians(sap1.dp-180))
v=1*np.cos(np.radians(sap1.dp-180))
plt.plot(sap1.hs)
fig, ax = plt.subplots(figsize=(11,9))
surf = ax.quiver(sap1.index.astype(np.int64)[::3],sap1.hs[::3],u[::3],v[::3],sap1.tp[::3],zorder=1)
ax.quiver(sap1.index.astype(np.int64)[::3],sap1.hs[::3],u[::3],v[::3],edgecolor='k', facecolor='None', linewidth=.5)
ax.plot(sap1.index.astype(np.int64),sap1.hs,'gray',linewidth=3,zorder=0)
ax.grid(), ax.set_ylabel('Significant Wave Height (m)');ax.set_ylim([0,8])
cbar=fig.colorbar(surf,orientation='vertical')
cbar.set_label(label='Peak Period (s)',size=14)
cbar.ax.tick_params(labelsize=12)
此代码的主要目标是获得类似于此图像的内容(但x轴应为日期而不是星期几):
由于某些原因,当我尝试使用plt.plot或fig时,我不明白,ax向我返回此错误:
FileNotFoundError:[WinError 2]系统找不到指定的文件:
整个代码运行良好,我所有的变量都正常工作。唯一的问题是当我尝试专门使用plt.plot()
或fig, ax = plt.subplots(figsize=(11,9))
我在Windows 10计算机上使用python 3.6。
如果有人可以提供帮助,将不胜感激。
答案 0 :(得分:0)
对我来说,出现了同样的问题。 Python的老式重启解决了该问题。在我看来,重新启动内核还不够,但是完全重新启动就可以完成工作(我使用的是Spyder平台,然后重新启动)。