python的matplotlib的legend,Python matplotlib.legend方法代码示例

# 需要导入模块: import matplotlib [as 别名]

# 或者: from matplotlib import legend [as 别名]

def plot_chart(log_file, path_to_png, mode=PLOT_MODE.NORMAL):

mean_ap=0

phases, detected_mean_ap = parse_log(log_file)

if detected_mean_ap != None:

mean_ap=detected_mean_ap

print "Processing %s with mAP=%f" % (path_to_png, mean_ap)

plt.figure(1, figsize=(8, 32))

end_phase=min(len(phases), 4)

for phase_idx in range(0,end_phase):

phase=np.array(phases[phase_idx])

plt.subplot(411+phase_idx)

label = LABELS[phase_idx]

plt.title("%s%s"%( "mAP = %f "%mean_ap if phase_idx == 0 else "",str(label[phase_idx])))

for x_label,y_label in FIELDS[phase_idx]:

## TODO: more systematic color cycle for lines

color = [random.random(), random.random(), random.random()]

linewidth = 0.75

## If there too many datapoints, do not use marker.

## use_marker = False

use_marker = True

# if (mode==PLOT_MODE.MOVING_AVG):

x_data = [row[x_label] for row in phase]

y_data = [row[y_label] for row in phase]

if mode==PLOT_MODE.MOVING_AVG:

y_data=moving_average(y_data, 100)

elif mode == PLOT_MODE.BOTH:

marker = random_marker()

plt.plot(x_data, y_data, label=label, color=color,

marker=marker, linewidth=linewidth)

color = [random.random(), random.random(), random.random()]

y_data = moving_average(y_data, 100)

if not use_marker:

plt.plot(x_data, y_data, label = label, color = color,

linewidth = linewidth)

else:

marker = random_marker()

plt.plot(x_data, y_data, label = label, color = color,

marker = marker, linewidth = linewidth)

#legend_loc = get_legend_loc(chart_type)

#plt.legend(loc = legend_loc, ncol = 1) # ajust ncol to fit the space

#plt.xlabel(x_axis_field)

#plt.ylabel(y_axis_field)

# plt.annotate(fontsize='xx-small')

print "Saving...",

plt.savefig(path_to_png, dpi=600)

print "done"

plt.show()

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值