【问题标题】:Python Windrose Legend LabelsPython Windrose 图例标签
【发布时间】:2019-03-22 20:26:39
【问题描述】:

我正在尝试完全控制 Windrose 中的传奇;图例由 bin 控制,可以使用ax.info['bins'] 调用。但是,我想更改 bin 组的名称。

在网上找了下,唯一的解决办法就是编辑windrose的.py文件,编辑后重新导入python脚本。

Python Windrose legend bracket format and loc

我一直在寻找一种更简单的方法,因为我计划为脚本中的各种情节设置不同的 bin。到目前为止,我已经尝试过 labelset_label 似乎不起作用。

【问题讨论】:

    标签: python label legend rose-diagram


    【解决方案1】:

    通过在 ax.set_legend 中添加标签参数并更改脚本以接受该参数。我还添加了一个小验证,如果标签与句柄不匹配,则会显示错误。

    ax.set_legend(labels = ['T', 'S', 'M'], title="Failure Mode", loc="upper left")

        def get_labels(labels, decimal_places=1):
            _decimal_places = str(decimal_places)
    
            fmt = (
                "[%." + _decimal_places + "f " +
                ": %0." + _decimal_places + "f"
            )
    
            if labels is None:
                labels = np.copy(self._info['bins'])
                if locale.getlocale()[0] in ['fr_FR']:
                    fmt += '['
                else:
                    fmt += ')'
                labels = [fmt % (labels[i], labels[i + 1])
                    for i in range(len(labels) - 1)]
            else:
                if len(labels) != len(self._info['bins']) -1 :
                    print("ERROR")
                labels = labels
    
            return labels
    
    
        kwargs.pop('handles', None)
    
        decimal_places = kwargs.pop('decimal_places', 1)
        labels = kwargs.pop('labels', None)
    
        handles = get_handles()
        labels = get_labels(labels, decimal_places)
        self.legend_ = mpl.legend.Legend(self, handles, labels, loc, **kwargs)
        return self.legend_
    

    更多信息:Github issue solution

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-31
      • 2019-11-23
      • 1970-01-01
      相关资源
      最近更新 更多