• <legend id='wLWvs'><style id='wLWvs'><dir id='wLWvs'><q id='wLWvs'></q></dir></style></legend>
    <tfoot id='wLWvs'></tfoot>
        <bdo id='wLWvs'></bdo><ul id='wLWvs'></ul>

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

        向 hovertext 标签添加其他文本

        Adding additional text to the hovertext label(向 hovertext 标签添加其他文本)
          <bdo id='zKY57'></bdo><ul id='zKY57'></ul>

              <tbody id='zKY57'></tbody>

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

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

                • <legend id='zKY57'><style id='zKY57'><dir id='zKY57'><q id='zKY57'></q></dir></style></legend>

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

                  本文介绍了向 hovertext 标签添加其他文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我已经搜索了一段时间,但似乎找不到相关问题.有类似的问题,但没有什么能触及我想要用我拥有的代码做的事情的核心.

                  我正在尝试在 plotly 中向 hovertext 添加其他文本.到目前为止,这是我的代码:

                  将 pandas 导入为 pd将 numpy 导入为 np从 plotly.offline 导入 *init_notebook_mode(连接=真)graph1 = merge.groupby(['study_arm', 'visit_label'])['mjsn'].mean().unstack('study_arm')graph1.iplot(mode='lines+markers',符号=['菱形开口','方形开口','圆点','六边形开口'],尺寸=8,色阶='dark2',yTitle='ytitle',xTitle='xtitle',title='图表标题',悬停格式 = '.2f')hv = merge.groupby(['study_arm', 'visit_label']).size()打印(高压)

                  注意:合并"是数据框,显示在下面的示例数据中.

                  上面的代码给出了以下输出(注意:将鼠标悬停在时间点上会为每个跟踪提供一些信息,我拍了一张照片来展示它的样子).

                  我的问题是如何将表中的主题计数编号获取到每个时间点的每个跟踪的悬停文本(最好在悬停文本的第二行,看起来像N = x",其中 x 是主题编号来自图片中图表下方的表格).

                  这是我用来创建此图表和表格的虚拟数据集的示例:

                  subject_number 访问标签 mjsn study_arm20001 第 1 天 0 B20001 月 06 0.4 B20001 月 12 0.2 B20003 第 1 天 0 B20003 月 06 -0.9 B20003 月 12 -0.7 B20005 第 1 天 0 C20005 月 06 0.1 C20005 月 12 -0.1 C20007 第 1 天 0 天20007 月 06 0 日20007 月 12 -0.3 D20008 第 1 天 0 C20008 月 06 -0.3 C20008 月 12 -0.1 C20010 第 1 天 0 A20010 月 06 -0.6 A20010 月 12 -0.4 A

                  解决方案

                  您想为每个图表/跟踪设置 texthovertext 元素.text 和 hovertext 都可以在这里使用.您可能需要两者的原因可以在

                  I've searched for some time now and I can't seem to find a related question. There are similar questions, but nothing that gets to the heart of what I am trying to do with the code I have.

                  I am trying to add additional text to the hovertext in plotly. Here is my code so far:

                  import pandas as pd
                  import numpy as np
                  
                  from plotly.offline import *
                  init_notebook_mode(connected=True)
                  
                  graph1 = merged.groupby(['study_arm', 'visit_label'])['mjsn'].mean().unstack('study_arm')
                  graph1.iplot(mode='lines+markers',
                                   symbol=['diamond-open', 'square-open', 'circle-dot', 'hexagon-open'],
                                   size=8, colorscale = 'dark2', yTitle='ytitle', xTitle='xtitle',  
                                   title='Title of Graph',
                                   hoverformat = '.2f')
                  
                  
                  hv = merged.groupby(['study_arm', 'visit_label']).size()
                  print(hv)
                  

                  Note: 'merged' is the dataframe and is shown in the sample data below.

                  The code above gives the following output (note: hovering over the timepoint gives some information for each trace, and I took a picture to show what that looks like).

                  My question is how can I get the subject count number from the table into the hovertext for each trace at each timepoint (preferably on the second line of the hovertext that looks like 'N=x', where x is the subject number from the table under the graph in the picture).

                  Here is a sample of the dummy dataset I used to create this graph and table:

                  subject_number  visit_label mjsn    study_arm
                    20001         Day 1        0          B
                    20001         Month 06     0.4        B
                    20001         Month 12     0.2        B
                    20003         Day 1        0          B
                    20003         Month 06    -0.9        B
                    20003         Month 12    -0.7        B
                    20005         Day 1        0          C
                    20005         Month 06     0.1        C
                    20005         Month 12    -0.1        C
                    20007         Day 1        0          D
                    20007         Month 06     0          D
                    20007         Month 12    -0.3        D
                    20008         Day 1        0          C
                    20008         Month 06    -0.3        C
                    20008         Month 12    -0.1        C
                    20010         Day 1        0          A
                    20010         Month 06    -0.6        A
                    20010         Month 12    -0.4        A
                  

                  解决方案

                  You want to set the text or hovertext element for each chart/trace. Both text and hovertext will work here. The reason you may need both can be seen here. You may also want to change the hoverinfo element. Your options are 'x', 'y', 'none', 'text', 'all'. Additional resources are: text and annotations, docs, and python example. In addition, to get the count of cases at a time period I took two different groupby operations and then concatenated them together.

                  Example using your dataframe:

                  import plotly.graph_objs as go
                  from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
                  init_notebook_mode(connected=True)
                  import pandas as pd
                  
                  df = pd.DataFrame({
                      'subject_number' : [20001, 20001, 20001, 20003, 20003, 20003, 20005, 20005, 
                          20005, 20007, 20007, 20007, 20008, 20008, 20008, 20010, 20010, 20010], 
                  
                      'visit_label' : ['Day 1', 'Month 6', 'Month 12', 'Day 1', 'Month 6', 
                          'Month 12', 'Day 1', 'Month 6', 'Month 12', 'Day 1', 'Month 6',  
                          'Month 12', 'Day 1', 'Month 6', 'Month 12', 'Day 1', 'Month 6', 
                          'Month 12'],  
                  
                      'mjsn':[0, 0.4, 0.2, 0, -0.9, -0.7, 0, 0.1, -0.1, 0, 0, -0.3, 0, -0.3, -0.1,
                          0, -0.6, -0.4], 
                  
                      'study_arm':['B', 'B', 'B', 'B', 'B', 'B', 'C', 'C', 'C', 'D', 'D', 'D', 
                          'C', 'C', 'C', 'A', 'A', 'A']
                      })
                  
                  
                  
                  grouped = df.groupby(['study_arm', 'visit_label'])
                  tmp1 = grouped.mean()["mjsn"]
                  tmp2 = grouped.count()["subject_number"]
                  output_df = pd.concat([tmp1, tmp2], axis = 1)
                  
                  data = []
                  for study in output_df.index.get_level_values(0).unique():
                      trace = go.Scatter(
                          x = output_df.loc[study, :].index,
                          y = output_df.loc[study, "mjsn"],
                          hovertext= ["msjn:{0}<br>subject:{1}".format(x, int(y)) 
                                      for x,y in zip(output_df.loc[study, "mjsn"],
                                          output_df.loc[study, "subject_number"])],
                          mode = 'lines+markers',
                          hoverinfo = 'text'
                      )
                      data += [trace]
                  #
                  iplot(data)
                  

                  Similar SO questions are here and here

                  这篇关于向 hovertext 标签添加其他文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)
                  Pandas: How to easily share a sample dataframe using df.to_dict()?(Pandas:如何使用 df.to_dict() 轻松共享示例数据框?)
                  PYODBC to Pandas - DataFrame not working - Shape of passed values is (x,y), indices imply (w,z)(PYODBC 到 Pandas - DataFrame 不起作用 - 传递值的形状是(x,y),索引暗示(w,z))
                  Scikit-learn labeled dataset creation from segmented time series(从分段时间序列创建 Scikit-learn 标记数据集)
                  Chunking, processing amp; merging dataset in Pandas/Python(分块、处理和在 Pandas/Python 中合并数据集)
                  TypeError: object of type #39;numpy.int64#39; has no len()(TypeError:“numpy.int64类型的对象没有 len())
                    <tbody id='fKgfq'></tbody>

                    • <legend id='fKgfq'><style id='fKgfq'><dir id='fKgfq'><q id='fKgfq'></q></dir></style></legend>

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

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