为了账号安全,请及时绑定邮箱和手机立即绑定

使用 matplotlib 代理艺术家向平行坐标图添加图例

使用 matplotlib 代理艺术家向平行坐标图添加图例

达令说 2021-09-28 15:47:41
我很难将图例添加到matplotlib.pyplot,我的目标是使平行坐标图类似于那个由于我的用例类似,我使用了提供的解决方案,除了我只有 2 个观察值,每组 1 个并且我添加了 plt.legend(axes,style),以便创建图例,但是当我运行代码时,我收到以下警告并且没有传奇。:\Python27\lib\site-packages\matplotlib\legend.py:634: UserWarning: Legend 不支持实例。可以使用代理艺术家来代替。请参阅:http : //matplotlib.org/users/legend_guide.html#using-proxy-artist "#using-proxy-artist".format(orig_handle)我试图通过文档但找不到解决方案。我发现下面列出的另一个stackoverflow帖子,但仍然不太清楚图例的使用,特别是在传递给图例函数之前如何解包子图。任何人都可以请解释它是如何工作的。#!/usr/bin/pythonimport matplotlib.pyplot as pltimport matplotlib.ticker as tickerdef parallel_coordinates(data_sets, style=None):    dims = len(data_sets[0])    x    = range(dims)    fig, axes = plt.subplots(1, dims-1, sharey=False)    if style is None:        style = ['r-']*len(data_sets)    # Calculate the limits on the data    min_max_range = list()    for m in zip(*data_sets):        mn = min(m)        mx = max(m)        if mn == mx:            mn -= 0.5            mx = mn + 1.        r  = float(mx - mn)        min_max_range.append((mn, mx, r))    # Normalize the data sets    norm_data_sets = list()    for ds in data_sets:        nds = [(value - min_max_range[dimension][0]) /                 min_max_range[dimension][2]                 for dimension,value in enumerate(ds)]        norm_data_sets.append(nds)    data_sets = norm_data_sets    # Plot the datasets on all the subplots    for i, ax in enumerate(axes):        for dsi, d in enumerate(data_sets):            ax.plot(x, d, style[dsi])        ax.set_xlim([x[i], x[i+1]])    # Set the x axis ticks     for dimension, (axx,xx) in enumerate(zip(axes, x[:-1])):        axx.xaxis.set_major_locator(ticker.FixedLocator([xx]))        ticks = len(axx.get_yticklabels())        labels = list()        step = min_max_range[dimension][2] / (ticks - 1)        mn   = min_max_range[dimension][0]        for i in xrange(ticks):            v = mn + i*step            labels.append('%4.2f' % v)        axx.set_yticklabels(labels)
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 239 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号