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

        <tfoot id='SRu0q'></tfoot>

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

        如何在 for 循环内的 Plotly 中注释子图

        How to annotate subplots in Plotly inside a for loop(如何在 for 循环内的 Plotly 中注释子图)
          <tbody id='opAQD'></tbody>
          1. <i id='opAQD'><tr id='opAQD'><dt id='opAQD'><q id='opAQD'><span id='opAQD'><b id='opAQD'><form id='opAQD'><ins id='opAQD'></ins><ul id='opAQD'></ul><sub id='opAQD'></sub></form><legend id='opAQD'></legend><bdo id='opAQD'><pre id='opAQD'><center id='opAQD'></center></pre></bdo></b><th id='opAQD'></th></span></q></dt></tr></i><div id='opAQD'><tfoot id='opAQD'></tfoot><dl id='opAQD'><fieldset id='opAQD'></fieldset></dl></div>

            <tfoot id='opAQD'></tfoot>
          2. <small id='opAQD'></small><noframes id='opAQD'>

              <legend id='opAQD'><style id='opAQD'><dir id='opAQD'><q id='opAQD'></q></dir></style></legend>

                  <bdo id='opAQD'></bdo><ul id='opAQD'></ul>
                  本文介绍了如何在 for 循环内的 Plotly 中注释子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试在 for 循环中注释我的子图.每个子图将在图上打印 RMS 值.我尝试通过以下方式做到这一点:

                  I am trying to annotate my subplots inside a for loop. Each subplot will have RMS value printed on the plot. I tried to do it the following way:

                  from plotly import tools
                  figg = tools.make_subplots(rows=4, cols=1)
                  
                  fake_date = {"X":   np.arange(1, 101, 0.5), "Y": np.sin(x), "Z": [x + 1 for x in range(10)] * 20}
                  fake_date = pd.DataFrame(fake_date)
                  fake_date.sort_values("Z")
                  
                  unique_ids = fake_date['Z'].unique()
                  train_id, test_id = np.split(np.random.permutation(unique_ids), [int(.6 * len(unique_ids))])
                  
                  
                  for i, j in enumerate(test_id):
                  
                      x_test = fake_date[fake_date['Z'].isin([test_id[i]])] 
                      y_test = fake_date[fake_date['Z'].isin([test_id[i]])]
                  
                  
                      # Evaluate 
                      rms_test = 0.04
                      r_test = 0.9
                  
                  
                  
                      Real = {'type' : 'scatter',
                                       'x' : x_test.X,
                                       'y' : x_test.Y,
                                  "mode" : 'lines+markers', 
                                  "name" : 'Real'}
                  
                  
                  
                  
                      figg.append_trace(Real, i+1, 1)
                  
                  
                  figg['layout'].update( annotations=[dict(x = 10,y = 0.2,  text= rms_test, xref= "x1",yref="y1")]  )
                  figg['layout'].update(height=1800, width=600, title='Testing')
                  pyo.iplot(figg)
                  

                  这不起作用,尽管给出的答案 这里 似乎对其他人有用.谁能指出我做错了什么?我为重现性生成了假日期

                  This does not work, although the answer given here seems to work for others. Can anyone point out what wrong am I doing? I generated fake date for reproducibility

                  推荐答案

                  我不确定 RMS 值的准确位置,但下面是一个示例代码,可以帮助您实现您想要的.

                  I am not sure where to exactly place the RMS value, but below is a sample code which will help you achieve what you want.

                  我们创建一个数组annotation_arr,我们使用for循环在其中存储注释.

                  We create an array annotation_arr where we store the annotations using the for loop.

                  我们需要为每个单独的轴设置 xvalyval.请记住,第一个轴是 x,第二个是 x2 所以,我为此写了一个三元条件,请查看下面的代码,如果有的话请告诉我问题!

                  We need to set the xval and yval for each of the individual axes. Remember, first axis will be x, second will be x2 so, I have written a ternary condition for that, please checkout the below code and let me know if there is any issues!

                  import plotly.graph_objs as go
                  from plotly.offline import download_plotlyjs,init_notebook_mode,plot,iplot
                  from plotly import tools
                  import numpy as np
                  import pandas as pd
                  init_notebook_mode(connected=True)
                  rows = 4
                  figg = tools.make_subplots(rows=rows, cols=1)
                  
                  fake_date = {"X":   np.arange(0, 100, 0.5), "Y": [np.sin(x) for x in range(200)], "Z": [x + 1 for x in range(10)] * 20}
                  fake_date = pd.DataFrame(fake_date)
                  fake_date.sort_values("Z")
                  
                  unique_ids = fake_date['Z'].unique()
                  train_id, test_id = np.split(np.random.permutation(unique_ids), [int(.6 * len(unique_ids))])
                  top = 0
                  annotation_arr = []
                  for i, j in enumerate(test_id):
                  
                      x_test = fake_date[fake_date['Z'].isin([test_id[i]])] 
                      y_test = fake_date[fake_date['Z'].isin([test_id[i]])]
                  
                  
                      # Evaluate 
                      rms_test = 0.04
                      r_test = 0.9
                  
                  
                  
                      Real = {'type' : 'scatter',
                                       'x' : x_test.X,
                                       'y' : x_test.Y,
                                  "mode" : 'lines+markers', 
                                  "name" : 'Real'}
                  
                  
                      top = top + 1/rows
                      i_val = "" if i == 0 else i + 1
                      annotation_arr.append(dict(x = r_test,y = top,  text= rms_test, xref= "x"+str(i_val),yref="y"+str(i_val)))
                      figg.append_trace(Real, i+1, 1)
                  
                  
                  figg['layout'].update( annotations=annotation_arr  )
                  figg['layout'].update(height=1800, width=600, title='Testing')
                  iplot(figg)
                  

                  这篇关于如何在 for 循环内的 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 数据框制作线图?)

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

                        <tbody id='Cw7er'></tbody>
                      <tfoot id='Cw7er'></tfoot>
                    • <legend id='Cw7er'><style id='Cw7er'><dir id='Cw7er'><q id='Cw7er'></q></dir></style></legend>
                        <bdo id='Cw7er'></bdo><ul id='Cw7er'></ul>
                        1. <small id='Cw7er'></small><noframes id='Cw7er'>