<small id='9ADBX'></small><noframes id='9ADBX'>

  • <legend id='9ADBX'><style id='9ADBX'><dir id='9ADBX'><q id='9ADBX'></q></dir></style></legend>
    1. <i id='9ADBX'><tr id='9ADBX'><dt id='9ADBX'><q id='9ADBX'><span id='9ADBX'><b id='9ADBX'><form id='9ADBX'><ins id='9ADBX'></ins><ul id='9ADBX'></ul><sub id='9ADBX'></sub></form><legend id='9ADBX'></legend><bdo id='9ADBX'><pre id='9ADBX'><center id='9ADBX'></center></pre></bdo></b><th id='9ADBX'></th></span></q></dt></tr></i><div id='9ADBX'><tfoot id='9ADBX'></tfoot><dl id='9ADBX'><fieldset id='9ADBX'></fieldset></dl></div>
      <tfoot id='9ADBX'></tfoot>

        • <bdo id='9ADBX'></bdo><ul id='9ADBX'></ul>
      1. 如何避免重复的图例标签或通过自定义图例标签

        How to avoid duplicate legend labels in plotly or pass custom legend labels(如何避免重复的图例标签或通过自定义图例标签)

            <tbody id='T0teJ'></tbody>
          • <legend id='T0teJ'><style id='T0teJ'><dir id='T0teJ'><q id='T0teJ'></q></dir></style></legend>

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

                <bdo id='T0teJ'></bdo><ul id='T0teJ'></ul>

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

                1. 本文介绍了如何避免重复的图例标签或通过自定义图例标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如何避免子图中重复的图例标签?我在 matplotlib 中进行此操作的一种方法是将自定义图例标签传递给图例对象.我在 plotly 中找不到任何等效选项的文档.有任何想法吗?

                  How can I avoid duplicate legend labels in subplots? One way I would go about it in matplotlib would be to pass custom legend labels to an legend object. I couldn't find any documentation for an equivalent option in plotly. Any ideas?

                  traces = []
                  
                  colors = {'Iris-setosa': 'rgb(31, 119, 180)', 
                            'Iris-versicolor': 'rgb(255, 127, 14)', 
                            'Iris-virginica': 'rgb(44, 160, 44)'}
                  
                  for col in range(4):
                      for key in colors:
                          traces.append(Histogram(x=X[y==key, col], 
                                          opacity=0.75,
                                          xaxis='x%s' %(col+1),
                                          marker=Marker(color=colors[key]),
                                          name=key
                                          )
                                       )
                  
                  data = Data(traces)
                  
                  layout = Layout(barmode='overlay',
                                  xaxis=XAxis(domain=[0, 0.25], title='sepal length (cm)'),
                                  xaxis2=XAxis(domain=[0.3, 0.5], title='sepal width (cm)'),
                                  xaxis3=XAxis(domain=[0.55, 0.75], title='petal length (cm)'),
                                  xaxis4=XAxis(domain=[0.8, 1], title='petal width (cm)'),
                                  yaxis=YAxis(title='count'),
                                  title='Distribution of the different Iris flower features')
                  
                  fig = Figure(data=data, layout=layout)
                  
                  py.iplot(fig)
                  

                  推荐答案

                  Plotly 在跟踪级别控制这个.尝试在您不想出现在图例中的 Histogram 跟踪中传入 showlegend=False.

                  Plotly controls this on the trace level. Try passing in showlegend=False inside the Histogram traces that you don't want to appear in the legend.

                  参考:https://plot.ly/python/reference/#Histogram-showlegend

                  示例:https://plot.ly/python/legend/#Hiding-图例条目

                  从上面的链接直接复制粘贴.

                  Direct copy-paste from the link above.

                  import plotly.plotly as py
                  from plotly.graph_objs import *
                  # Fill in with your personal username and API key
                  # or, use this public demo account
                  py.sign_in('Python-Demo-Account', 'gwt101uhh0')
                  
                  trace1 = Scatter(
                      x=[0, 1, 2],
                      y=[1, 2, 3],
                      name='First Trace',
                      showlegend=False
                  )
                  trace2 = Scatter(
                      x=[0, 1, 2, 3],
                      y=[8, 4, 2, 0],
                      name='Second Trace',
                      showlegend=True
                  )
                  data = Data([trace1, trace2])
                  plot_url = py.plot(data, filename='show-legend')
                  

                  你想看到的用法在上面的trace1中.

                  The usage you want to see is shown in trace1 above.

                  这篇关于如何避免重复的图例标签或通过自定义图例标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                  Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                  python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                  Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                  How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                      <tbody id='7yL1p'></tbody>

                    <tfoot id='7yL1p'></tfoot>

                      <bdo id='7yL1p'></bdo><ul id='7yL1p'></ul>
                      1. <small id='7yL1p'></small><noframes id='7yL1p'>

                      2. <i id='7yL1p'><tr id='7yL1p'><dt id='7yL1p'><q id='7yL1p'><span id='7yL1p'><b id='7yL1p'><form id='7yL1p'><ins id='7yL1p'></ins><ul id='7yL1p'></ul><sub id='7yL1p'></sub></form><legend id='7yL1p'></legend><bdo id='7yL1p'><pre id='7yL1p'><center id='7yL1p'></center></pre></bdo></b><th id='7yL1p'></th></span></q></dt></tr></i><div id='7yL1p'><tfoot id='7yL1p'></tfoot><dl id='7yL1p'><fieldset id='7yL1p'></fieldset></dl></div>
                        • <legend id='7yL1p'><style id='7yL1p'><dir id='7yL1p'><q id='7yL1p'></q></dir></style></legend>