本文整理汇总了Python中matplotlib.legend方法的典型用法代码示例。如果您正苦于以下问题:Python matplotlib.legend方法的具体用法?Python matplotlib.legend怎么用?Python matplotlib.legend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类matplotlib
的用法示例。
在下文中一共展示了matplotlib.legend方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_legend
# 需要导入模块: import matplotlib [as 别名]
# 或者: from matplotlib import legend [as 别名]
def get_legend(self):
"""Return the `Legend` instance, or None if no legend is defined."""
return self.legend_
示例2: plot_chart
# 需要导入模块: 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()