• <tfoot id='k7vzI'></tfoot>

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

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

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

      2. Plotly 中的行悬停文本

        Line hover text in Plotly(Plotly 中的行悬停文本)
            <tbody id='0La6h'></tbody>
        • <i id='0La6h'><tr id='0La6h'><dt id='0La6h'><q id='0La6h'><span id='0La6h'><b id='0La6h'><form id='0La6h'><ins id='0La6h'></ins><ul id='0La6h'></ul><sub id='0La6h'></sub></form><legend id='0La6h'></legend><bdo id='0La6h'><pre id='0La6h'><center id='0La6h'></center></pre></bdo></b><th id='0La6h'></th></span></q></dt></tr></i><div id='0La6h'><tfoot id='0La6h'></tfoot><dl id='0La6h'><fieldset id='0La6h'></fieldset></dl></div>
          • <bdo id='0La6h'></bdo><ul id='0La6h'></ul>

                <legend id='0La6h'><style id='0La6h'><dir id='0La6h'><q id='0La6h'></q></dir></style></legend>
                  <tfoot id='0La6h'></tfoot>

                  <small id='0La6h'></small><noframes id='0La6h'>

                  本文介绍了Plotly 中的行悬停文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在使用 Plotly 绘制一个类似于 Plotly 网站上的示例的图表.
                  除了图形节点上的悬停文本外,我还希望在边缘上有一个悬停文本.

                  I am plotting a graph with Plotly similar to the example on the Plotly website.
                  Along with the hover text on the graph nodes, I want to have a hover text on the edges as well.

                  我试图通过添加一个名称"字段来修改边缘的跟踪对象来实现这一点,但这不起作用并且将名称"放在节点上.

                  I tried to achieve this by modifying the trace object for edges by adding a 'name' field, but this didn't work and was putting the 'name' on the nodes.

                  trace3=Scatter(
                      x=Xed,
                      y=Yed,
                      name="my_hover_text",
                      mode='lines',
                      line=Line(color='rgb(210,210,210)', width=1),
                      hoverinfo='name'
                  )
                  

                  使用文本"字段而不是名称"字段,结果完全相同.

                  Using the 'text' field instead of the 'name' field, gives the very same result.

                  我还尝试为每个边缘单独跟踪,这应该可以解决关于将名称放在何处的混淆,但这让我无处可去.
                  作为底线,我需要一种将(悬停)标签/文本放在连接两点的线上的方法.

                  I have also tried to have a separate trace for each edge, which should solve the confusion about where to put the name on the line, but this lead me nowhere.
                  As a bottom line, I need a way to put a (hover) label/text on a line connecting two points.

                  推荐答案

                  一个快速的解决方案/hack 是遵循 艾蒂安的想法.
                  这个想法是在每一行上插入一个透明节点并用悬停文本标签对其进行注释.

                  One quick solution/hack is to follow etienne's idea from the community forum page that Maximilian mentioned in the comment.
                  The idea is to insert a transparent node on each line and annotate it with a hover text label.

                  这是一个对我有用的代码

                  here is a code that worked for me

                  trace3_list = []
                  middle_node_trace = go.Scatter(
                      x=[],
                      y=[],
                      text=[],
                      mode='markers',
                      hoverinfo='text',
                      marker=go.Marker(
                          opacity=0
                      )
                  )
                  for edge in G.edges(data=True):
                      trace3=Scatter(
                          x=[],
                          y=[],
                          mode='lines',
                          line=Line(color='rgb(210,210,210)', width=edge[2]['weight']),
                          hoverinfo='none'
                      )
                      x0, y0 = G.node[edge[0]]['pos']
                      x1, y1 = G.node[edge[1]]['pos']
                      trace3['x'] += [x0, x1, None]
                      trace3['y'] += [y0, y1, None]
                      trace3_list.append(trace3)
                  
                      middle_node_trace['x'].append((x0+x1)/2)
                      middle_node_trace['y'].append((y0+y1)/2)
                      middle_node_trace['text'].append(str(edge[2]['weight']))
                  

                  然后只绘制所有轨迹,即 [*trace3_list, middle_node_trace].

                  Then just plot all the traces, i.e. [*trace3_list, middle_node_trace].

                  奖励:每个边缘都有单独的轨迹允许设置不同的宽度,例如与边缘权重成正比.

                  BONUS: having a separate trace for each edge allows to set different widths, e.g. proportional to the edge weight.

                  这篇关于Plotly 中的行悬停文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)

                    <legend id='9p89Y'><style id='9p89Y'><dir id='9p89Y'><q id='9p89Y'></q></dir></style></legend>

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

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

                      <tbody id='9p89Y'></tbody>

                    • <bdo id='9p89Y'></bdo><ul id='9p89Y'></ul>

                      <tfoot id='9p89Y'></tfoot>