- 积分
- 697
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2011-9-24
- 最后登录
- 1970-1-1
|
登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
本帖最后由 须佐能乎 于 2018-11-8 11:19 编辑
小弟玩儿蛇小白,用matplotlib画图发现坐标脊有时候出现,有时候不出现,请求论坛上的大大们指点迷津
问题一:同样的程序,用循环画图,第一次画出来的有坐标脊,底色也是白色的,网格线是黑色的,但是第二次循环画出来的坐标脊就没了,底色也变成灰色,网格线也是白的,而且图例的位置也变化了,这是什么情况啊
画图部分代码如下:
def plot_time(df):
print("plot_time")
global name,has_thresh,out_path,description,test_time,data_name,\
begin_time,end_time,CTC_var,test_var,VX_MASK
dict_info = get_info(df)
# time = time_format_change(dict_info['FCST_VALID_BEG'],1)
lead = dict_info['FCST_LEAD']
time = map(format,lead)
points = dict_info['INTERP_PNTS']
length = grid2km(points)
thresh = handing_list(dict_info['FCST_THRESH'])
#有阈值或有邻域半径
if has_thresh == 'TRUE':
print(name + ' has_thresh is TRUE')
for j in range(len(points)):
# fig = plt.figure(figsize=(17,12))
fig,ax = plt.subplots(figsize=(17,12))
df_j = df[(df['INTERP_PNTS'] == points[j])]
for i in thresh:
df_i = df_j[(df_j['FCST_THRESH'] == i)]
y = format_list(list(df_i[name]))
x = time
#plot lines
plt.plot(x,y,linewidth=3.5)
#asix 刻度设置
plt.xticks(fontsize=16)#,rotation=60
plt.yticks(fontsize=16)
#设置y轴取值范围
#plt.ylim(0,1)
#设置x轴和y轴标签
plt.xlabel('TIME(H)',fontsize=24)
plt.ylabel(description,fontsize=24)
ax.spines["bottom"].set_color("black")
ax.spines["left"].set_color("black")
ax.spines["top"].set_color("black")
ax.spines["right"].set_color("black")
#添加时间小标题
Begin = "Begin: " + begin_time
End = "End: " + end_time
plt.title(Begin+ "\n" + End, loc='right',fontsize=16)
plt.title("NWP "+str(length[j])+"KM Forecast Grid Verification",\
loc='center',fontsize=26,fontdict={'weight':'bold'})
#显示网格
# plt.grid(True,ls=":",lw=1,color="gray",alpha=0.5)
plt.grid()
#显示图例
plt.legend(thresh,fontsize=16,framealpha=1\
,bbox_to_anchor=(1,0.7))#loc='upper right'
#保存图片
path = out_path + VX_MASK + "//"+ test_time + "//grid//" + \
data_name + "//"
mkdir(path)
filename = path + test_var +"_TIME_" + name + "_NBR" +\
str(length[j]).zfill(2) + "KM_B" + begin_time + "-E" +\
end_time + ".png"
plt.savefig(filename)
plt.close()
print(filename)
问题二:小白使用了坐标脊控制的spines属性设置了坐标脊的颜色,但是画出的图仍然是灰低,没边框,这是为啥啊
画图代码是:
#plot length list picture
def plot_nbr(df):
print("plot_nbr")
global name,has_thresh,out_path,description,interval,test_time,data_name,\
begin_time,end_time,CTC_var,test_var,VX_MASK
dict_info = get_info(df)
time = dict_info['FCST_VALID_BEG']
lead = dict_info['FCST_LEAD']
points = dict_info['INTERP_PNTS']
length = grid2km(points)
thresh = handing_list(dict_info['FCST_THRESH'])
if len(points) > 1:
for j in range(len(lead)):
# df_j = df[(df['FCST_VALID_BEG'] == time[j])]
df_j = df[(df['FCST_LEAD'] == lead[j])]
# fig = plt.figure(figsize=(17,12))
fig,ax = plt.subplots(figsize=(17,12))
for i in range(len(thresh)):
df_i = df_j[(df_j['FCST_THRESH'] == thresh)]
if name in CTC_var:
A = format_list(list(df_i['FY_OY']))
B = format_list(list(df_i['FY_ON']))
C = format_list(list(df_i['FN_OY']))
D = format_list(list(df_i['FN_ON']))
if name == 'TS':
y = TS(A,B,C)
elif name == 'PO':
y = PO(A,B,C)
elif name == 'FAR':
y = FAR(A,B,C)
elif name == 'PC':
y = PC(A,B,C,D)
elif name == 'ETS':
y = ETS(A,B,C,D)
else:
y = format_list(list(df_i[name]))
x = length
plt.plot(x,y,linewidth=3.5)
#asix 刻度设置
label = length[::interval]
plt.xticks(label,fontsize=16)
plt.yticks(fontsize=16)
# 坐标脊
ax.spines["bottom"].set_color("black")
ax.spines["left"].set_color("black")
ax.spines["top"].set_color("black")
ax.spines["right"].set_color("black")
#设置y轴取值范围
#plt.ylim(0,1)
#设置x轴和y轴标签
plt.xlabel('Length scale(km)',fontsize=24)
plt.ylabel(description,fontsize=24)
#添加时间小标题
Begin = "Begin: " + begin_time
End = "End: " + end_time
plt.title(Begin+ "\n" + End, loc='right',fontsize=16)
#print(str(lead[j]/1000))
plt.title("NWP " + str(lead[j]/10000).zfill(2) +\
"H Forecast Grid Verification",loc='center',fontsize=26,\
fontdict={'weight':'bold'})
#设置网格
plt.grid(True)
# 设置图例
plt.legend(thresh,fontsize=16,framealpha=1,loc='right')
#bbox_to_anchor=(1,0.7)
#保存图片
path = out_path + VX_MASK + "//"+ test_time + "//grid//" + \
data_name + "//"
mkdir(path)
filename=path + test_var + "_NBR_" + str(lead[j]/10000).zfill(2)+\
"H_" + name + "_B" + begin_time + "-E" + end_time + ".png"
plt.savefig(filename)
plt.close()
print(filename)
else:
print('No enough INTERP_PNTS data to plot!')
return None
|
-
问题一的第一次循环
-
问题一的第二次循环
-
问题二的图
|