<bdo id='F9D9R'></bdo><ul id='F9D9R'></ul>
  • <small id='F9D9R'></small><noframes id='F9D9R'>

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

        在每个子图旁边绘制图例,Python

        Plotly legend next to each subplot, Python(在每个子图旁边绘制图例,Python)

          • <bdo id='5zrwa'></bdo><ul id='5zrwa'></ul>

            <small id='5zrwa'></small><noframes id='5zrwa'>

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

          • <legend id='5zrwa'><style id='5zrwa'><dir id='5zrwa'><q id='5zrwa'></q></dir></style></legend>
                • <tfoot id='5zrwa'></tfoot>
                  本文介绍了在每个子图旁边绘制图例,Python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在注意到这个问题目前没有答案后,我想知道是否有人知道如何:

                  After noticing that there was no answer to this question at the moment, I would like to know if anyone has an idea how to:

                  1. 每个子图都有一个图例.
                  2. 按名称分组图例.(例如:对于不同的子图,都具有相同的两条曲线但具有不同的值).

                  这是我的 Plotly 脚本:

                  Here's my Plotly script:

                  from plotly import tools
                  import plotly.plotly as py
                  import plotly.graph_objs as go
                  import plotly
                  nom_plot=[]
                  
                  trace1 = go.Scatter(x=[1, 2, 3], y=[4, 5, 6],name='1',showlegend=True)
                  nom_plot.append('GRAPH 1')
                  trace2 = go.Scatter(x=[20, 30, 40], y=[50, 60, 70],name='2',yaxis='y2')
                  nom_plot.append('GRAPH 2')
                  trace3 = go.Scatter(x=[300, 400, 500], y=[600, 700, 800],showlegend=False)
                  nom_plot.append('GRAPH 3')
                  trace4 = go.Scatter(x=[4000, 5000, 6000], y=[7000, 8000, 9000])
                  nom_plot.append('GRAPH 4')
                  trace5 = go.Scatter(x=[20, 30, 40], y=[50, 60, 70])
                  nom_plot.append('GRAPH 5')
                  
                  print(trace1)
                  
                  
                  
                  fig = tools.make_subplots(rows=4, cols=2, subplot_titles=(nom_plot))
                  
                  fig.append_trace(trace1, 1, 1)
                  fig['layout']['xaxis1'].update(title='xaxis 1 title')
                  fig.append_trace(trace2, 1, 1)
                  fig.append_trace(trace3, 2, 1)
                  fig.append_trace(trace4, 2, 2)
                  fig['layout']['yaxis3'].update(title='yaxis 3 title')
                  fig.append_trace(trace5, 3, 1)
                  
                  
                  fig['layout']['yaxis2'].update(
                      overlaying='y1',
                      side='right', 
                      anchor='x1',
                      # domain=[0.15, 1],
                      range=[2, 6],
                      # zeroline=False,
                      showline=True, 
                      showgrid=False,
                      title='yaxis 3 title'
                  )
                  
                  fig['layout'].update(height=1000, width=1000, title='Multiple Subplots' +' with Titles')
                  
                  
                  plotly.offline.plot(fig, filename='multiple-y-subplots6.html')
                  

                  这是我得到的(使用上面的 Plotly 脚本):

                  This what I obtain (Using Plotly Script above):

                  这就是我想要的(Pygal 制作):

                  And this is what I want (Made by Pygal):

                  推荐答案

                  解决方案是创建一个 HTML 文件,将离线渲染为 html 文件的多个图表合并:

                  The solution is to create an HTML file that merge sevral charts offline rendered as html files:

                  import plotly
                  import plotly.offline as py
                  import plotly.graph_objs as go
                  
                  fichier_html_graphs=open("DASHBOARD.html",'w')
                  fichier_html_graphs.write("<html><head></head><body>"+"
                  ")
                  
                  i=0
                  while 1:
                      if i<=40:
                          i=i+1
                  
                  
                          #______________________________--Plotly--______________________________________
                  
                  
                          color1 = '#00bfff'
                          color2 = '#ff4000'
                  
                          trace1 = go.Bar(
                              x = ['2017-09-25','2017-09-26','2017-09-27','2017-09-28','2017-09-29','2017-09-30','2017-10-01'],
                              y = [25,100,20,7,38,170,200],
                              name='Debit',
                              marker=dict(
                                  color=color1
                              )
                  
                          )
                          trace2 = go.Scatter(
                  
                              x=['2017-09-25','2017-09-26','2017-09-27','2017-09-28','2017-09-29','2017-09-30','2017-10-01'],
                              y = [3,50,20,7,38,60,100],
                              name='Taux',
                              yaxis='y2'
                  
                          )
                          data = [trace1, trace2]
                          layout = go.Layout(
                              title= ('Chart Number: '+str(i)),
                              titlefont=dict(
                              family='Courier New, monospace',
                              size=15,
                              color='#7f7f7f'
                              ),
                              paper_bgcolor='rgba(0,0,0,0)',
                              plot_bgcolor='rgba(0,0,0,0)',
                  
                              yaxis=dict(
                                  title='Bandwidth Mbit/s',
                                  titlefont=dict(
                                      color=color1
                                  ),
                                  tickfont=dict(
                                      color=color1
                                  )
                              ),
                              yaxis2=dict(
                                  title='Ratio %',
                                  overlaying='y',
                                  side='right',
                                  titlefont=dict(
                                      color=color2
                                  ),
                                  tickfont=dict(
                                      color=color2
                                  )
                  
                              )
                  
                          )
                          fig = go.Figure(data=data, layout=layout)
                          plotly.offline.plot(fig, filename='Chart_'+str(i)+'.html',auto_open=False)
                          fichier_html_graphs.write("  <object data=""+'Chart_'+str(i)+'.html'+"" width="650" height="500"></object>"+"
                  ")
                      else:
                          break
                  
                  fichier_html_graphs.write("</body></html>")
                  print("CHECK YOUR DASHBOARD.html In the current directory")
                  

                  结果:

                  这篇关于在每个子图旁边绘制图例,Python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

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

                    <tfoot id='KLv1S'></tfoot>
                      <tbody id='KLv1S'></tbody>

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

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