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

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

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

        <tfoot id='o6BIh'></tfoot>
      1. Plotly:如何在甘特图上标记条形?

        时间:2023-09-28
            <tbody id='15IHe'></tbody>

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

              <legend id='15IHe'><style id='15IHe'><dir id='15IHe'><q id='15IHe'></q></dir></style></legend>
              1. <tfoot id='15IHe'></tfoot>
                  本文介绍了Plotly:如何在甘特图上标记条形?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  有什么方法可以在 Plotly Gantt 图中创建条形图上的任务标签和 y 轴上的资源标签?

                  plotly.figure_factory.create_gantt的

                  解决方案

                  您可以根据设置在 fig['layout']['annotations'] 中添加结构为字典列表的注释就像

                  代码:

                  情节的结构与上面的源代码相似,但我已将其设置为在离线 Jupyter Notebook 中与 iplot() 一起使用.

                  # 导入从 plotly.offline 导入 download_plotlyjs, init_notebook_mode, plot, iplot从 IPython.core.display 导入显示,HTML将 plotly.figure_factory 导入为 ff导入 plotly.graph_objs# 设置display(HTML("<style>.container { width:50% !important; } .widget-select > select {background-color: gainboro;}</style>"))init_notebook_mode(连接=真)#%qtconsole --style vim# 日期开始A = '2009-01-01'StartB = '2009-03-05'StartC = '2009-02-20'FinishA='2009-02-28'FinishB='2009-04-15'FinishC='2009-05-30'标签日期A='2009-01-25'标签日期B='2009-03-20'LabelDateC='2009-04-01'# 样本数据df = [dict(Task="Task A", Start=StartA, Finish=FinishA),dict(Task="Task B", Start=StartB, Finish=FinishB),dict(Task="Task C", Start=StartC, Finish=FinishC)]# 数字图 = ff.create_gantt(df)# 添加注释annots = [dict(x=LabelDateA,y=0,text="任务标签 A", showarrow=False, font=dict(color='white')),dict(x=LabelDateB,y=1,text="任务标签 B", showarrow=False, font=dict(color='White')),dict(x=LabelDateC,y=2,text="任务标签 C", showarrow=False, font=dict(color='White'))]# 绘制图形fig['layout']['annotations'] = annotsiplot(无花果)

                  可能的改进:

                  如您所见,我已经硬编码了标签所在的日期.您可以轻松地计算中间日期开始和结束日期.但是为什么不简单地使用 (x=LabelDateC,y=2,align="center",text="Task label C", showarrow=False, font 中的 align=center 调整标签=dict(color='White'))?这不起作用,因为标签似乎附加到日期本身,而不是条的结构或大小.

                  Is there any way to create in Plotly Gantt chart with Task labels on bars and Resource labels on y-axis?

                  There is no such example in documentation of plotly.figure_factory.create_gantt. An abstract example of desirable chart is presented below:

                  解决方案

                  You can add annotations structured as a list of dictionaries in fig['layout']['annotations'] based on a setup like the first example from your link.

                  Plot:

                  Code:

                  The structure of the plot is similar to the source above, but I've set it up to work with iplot() in an off-line Jupyter Notebook.

                  # imports
                  from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
                  from IPython.core.display import display, HTML
                  import plotly.figure_factory as ff
                  import plotly.graph_objs as go
                  
                  # setup
                  display(HTML("<style>.container { width:50% !important; } .widget-select > select {background-color: gainsboro;}</style>"))
                  init_notebook_mode(connected=True)
                  
                  #%qtconsole --style vim
                  
                  # dates
                  StartA = '2009-01-01'
                  StartB = '2009-03-05'
                  StartC = '2009-02-20'
                  
                  FinishA='2009-02-28'
                  FinishB='2009-04-15'
                  FinishC='2009-05-30'
                  
                  LabelDateA='2009-01-25'
                  LabelDateB='2009-03-20'
                  LabelDateC='2009-04-01'
                  
                  # sample data
                  df = [dict(Task="Task A", Start=StartA, Finish=FinishA),
                        dict(Task="Task B", Start=StartB, Finish=FinishB),
                        dict(Task="Task C", Start=StartC, Finish=FinishC)]
                  
                  # figure
                  fig = ff.create_gantt(df)
                  
                  # add annotations
                  annots =  [dict(x=LabelDateA,y=0,text="Task label A", showarrow=False, font=dict(color='white')),
                             dict(x=LabelDateB,y=1,text="Task label B", showarrow=False, font=dict(color='White')),
                             dict(x=LabelDateC,y=2,text="Task label C", showarrow=False, font=dict(color='White'))]
                  
                  # plot figure
                  fig['layout']['annotations'] = annots
                  iplot(fig)
                  

                  Possible improvements:

                  As you can see, I've hard-coded the dates where the labels are positioned. You could just as easily calculate the middle date between the start and end dates. But why not simply adjust the labels using align=center in (x=LabelDateC,y=2,align="center",text="Task label C", showarrow=False, font=dict(color='White'))? That won't work because the label seems to be attached to the dates itself and not the structure or size of the bar.

                  这篇关于Plotly:如何在甘特图上标记条形?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                    <tbody id='yZgzD'></tbody>
                1. <tfoot id='yZgzD'></tfoot>
                    <bdo id='yZgzD'></bdo><ul id='yZgzD'></ul>
                  • <small id='yZgzD'></small><noframes id='yZgzD'>

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