python中fig_Python pyplot.figlegend方法代码示例

# 需要导入模块: 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}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值