# 需要导入模块: from matplotlib import pyplot [as 别名]
# 或者: from matplotlib.pyplot import figlegend [as 别名]
def _generate_plots(self, all_results, primary_regroup, secondary_regroup):
for figure_name, figure_data in self._regroup(all_results, **primary_regroup):
figure_data = self._regroup(figure_data, **secondary_regroup)
n_secondary = len(figure_data)
colors = plt.get_cmap(self.cmap)(np.linspace(0, 1.0, n_secondary))
fig = plt.figure(figure_name, figsize=self.figsize)
ax = fig.add_subplot(1, 1, 1)
if self.secondary == 'markers':
markers = self._marker_cycle()
patches = []
for (secondary_name, results), color, marker in zip(figure_data, colors, markers):
# recall-precision
data = np.array([result.data for result in results])
patches.append(self._plot(ax, data[..., 1], data[..., 0],
marker=self._marker(secondary_name) or marker,
color=self._color(secondary_name) or color,
label=self._t(secondary_name)))
plt.xlabel(self._t('recall'))
plt.ylabel(self._t('precision'))
self._set_lim(plt.ylim)
self._set_lim(plt.xlim)
fig.tight_layout()
else:
secondary_names, figure_data = zip(*figure_data)
scores = np.array([result.data for results in figure_data for result in results])
if tuple(self.metrics) == ('fscore',):
axis_label = 'fscore'
else:
axis_label = 'score'
axis_label = '{} {}'.format(self._t(figure_name), self._t(axis_label))
self._plot1d(ax, [(scores[..., c], kwargs) for c, kwargs in self._metric_data()],
[len(group) for group in figure_data], secondary_names, axis_label, secondary_regroup.get('label'))
plt.grid(axis='x' if self.secondary == 'rows' else 'y')
yield figure_name, fig, {}
if self.secondary == 'markers' and n_secondary > 1:
# XXX: this uses `ax` defined above
fig = plt.figure()
legend = plt.figlegend(*ax.get_axes().get_legend_handles_labels(), loc='center',
ncol=self._ncol(n_secondary),
prop=make_small_font())
fig.canvas.draw()
# FIXME: need some padding
bbox = legend.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
yield '_legend_', fig, {'bbox_inches': bbox}