<small id='rGueY'></small><noframes id='rGueY'>

    1. <legend id='rGueY'><style id='rGueY'><dir id='rGueY'><q id='rGueY'></q></dir></style></legend>

      <tfoot id='rGueY'></tfoot>
      • <bdo id='rGueY'></bdo><ul id='rGueY'></ul>
    2. <i id='rGueY'><tr id='rGueY'><dt id='rGueY'><q id='rGueY'><span id='rGueY'><b id='rGueY'><form id='rGueY'><ins id='rGueY'></ins><ul id='rGueY'></ul><sub id='rGueY'></sub></form><legend id='rGueY'></legend><bdo id='rGueY'><pre id='rGueY'><center id='rGueY'></center></pre></bdo></b><th id='rGueY'></th></span></q></dt></tr></i><div id='rGueY'><tfoot id='rGueY'></tfoot><dl id='rGueY'><fieldset id='rGueY'></fieldset></dl></div>
    3. 如何在海运图例中组合色调和样式组?

      How can I combine hue and style groups in a Seaborn legend?(如何在海运图例中组合色调和样式组?)
      <legend id='GIfZz'><style id='GIfZz'><dir id='GIfZz'><q id='GIfZz'></q></dir></style></legend>

          • <i id='GIfZz'><tr id='GIfZz'><dt id='GIfZz'><q id='GIfZz'><span id='GIfZz'><b id='GIfZz'><form id='GIfZz'><ins id='GIfZz'></ins><ul id='GIfZz'></ul><sub id='GIfZz'></sub></form><legend id='GIfZz'></legend><bdo id='GIfZz'><pre id='GIfZz'><center id='GIfZz'></center></pre></bdo></b><th id='GIfZz'></th></span></q></dt></tr></i><div id='GIfZz'><tfoot id='GIfZz'></tfoot><dl id='GIfZz'><fieldset id='GIfZz'></fieldset></dl></div>

              <small id='GIfZz'></small><noframes id='GIfZz'>

              <tfoot id='GIfZz'></tfoot>

                <tbody id='GIfZz'></tbody>
              • <bdo id='GIfZz'></bdo><ul id='GIfZz'></ul>
                本文介绍了如何在海运图例中组合色调和样式组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在为使用hue按";subscale";分组的纵向数据和使用style按";项目";分组的纵向数据绘制海运线条图。

                以下是我的代码(希望没有数据也可以理解):

                ax = sns.lineplot(data = df, x = 'Week', y = 'Value', style = 'Item', hue = 'Subscale', palette = 'colorblind', markers = True)
                plt.legend(bbox_to_anchor = (1.03, 1.02), fontsize = 10)
                

                这给我带来了这个情节:

                我想要的是合并子图例,以便它只显示";项目";的图例,但项目根据";subscale";着色,类似于:

                我创建这个失败了,所以如果你们中的任何人能帮忙,我将不胜感激!谢谢:)

                推荐答案

                如果我理解正确,某一类型的所有项目都有相同的分量表。因此,您已经拥有(或可以创建)将项目类型映射到相应小数位数的字典。

                Seborn为图例创建以下标签:

                • 字幕的‘subscale’
                • 每个分量表
                • 第二个副标题的‘Item’
                • 每一项

                每个标签对应于标识标记外观的句柄(&q;)。

                以下代码:

                • 查找'Item'的索引以能够拆分标签和句柄的数组
                • 提取"Subscale"的颜色
                • 将这些颜色应用于项目标记
                • 仅使用图例的项目
                import matplotlib.pyplot as plt
                import seaborn as sns
                import pandas as pd
                import numpy as np
                
                # first create some random data similar to the description
                np.random.seed(123)
                items = ['01', '04', '05', '06', '07', '10', '11', '13']
                N = len(items)
                subscale_dict = {'01': 'A', '04': 'C', '05': 'C', '06': 'C', '07': 'A', '10': 'B', '11': 'B', '13': 'A'}
                
                df = pd.DataFrame({'Week': np.tile(np.arange(7), N),
                                   'Value': np.random.rand(7 * N),
                                   'Item': np.repeat(items, 7)})
                df['Subscale'] = df['Item'].apply(lambda i: subscale_dict[i])
                df['Subscale'] = pd.Categorical(df['Subscale'])  # creates a fixed order
                
                # create the line plot as before
                ax = sns.lineplot(data=df, x='Week', y='Value', style='Item', hue='Subscale', palette='colorblind', markers=True)
                
                # create a dictionary mapping the subscales to their color
                handles, labels = ax.get_legend_handles_labels()
                index_item_title = labels.index('Item')
                color_dict = {label: handle.get_color()
                              for handle, label in zip(handles[1:index_item_title], labels[1:index_item_title])}
                
                # loop through the items, assign color via the subscale of the item idem
                for handle, label in zip(handles[index_item_title + 1:], labels[index_item_title + 1:]):
                    handle.set_color(color_dict[subscale_dict[ label]])
                
                # create a legend only using the items
                ax.legend(handles[index_item_title + 1:], labels[index_item_title + 1:], title='Item',
                          bbox_to_anchor=(1.03, 1.02), fontsize=10)
                
                plt.tight_layout()
                plt.show()
                

                这篇关于如何在海运图例中组合色调和样式组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                Grouping pandas DataFrame by 10 minute intervals(按10分钟间隔对 pandas 数据帧进行分组)
                  <i id='fNNdl'><tr id='fNNdl'><dt id='fNNdl'><q id='fNNdl'><span id='fNNdl'><b id='fNNdl'><form id='fNNdl'><ins id='fNNdl'></ins><ul id='fNNdl'></ul><sub id='fNNdl'></sub></form><legend id='fNNdl'></legend><bdo id='fNNdl'><pre id='fNNdl'><center id='fNNdl'></center></pre></bdo></b><th id='fNNdl'></th></span></q></dt></tr></i><div id='fNNdl'><tfoot id='fNNdl'></tfoot><dl id='fNNdl'><fieldset id='fNNdl'></fieldset></dl></div>
                    <bdo id='fNNdl'></bdo><ul id='fNNdl'></ul>

                    <small id='fNNdl'></small><noframes id='fNNdl'>

                      1. <legend id='fNNdl'><style id='fNNdl'><dir id='fNNdl'><q id='fNNdl'></q></dir></style></legend>
                        <tfoot id='fNNdl'></tfoot>
                            <tbody id='fNNdl'></tbody>