当前位置: 首页 > 知识库问答 >
问题:

带有色条的普雷蒂甘特图

吕自怡
2023-03-14

我正在制作这样的甘特图https://plot.ly/python/gantt/#index-然而,通过数值变量,我想用作索引的数值变量是一个大于100的正数。当我使用示例代码时,色条限制为[0100],导致色条全部为100色。有没有办法在使用示例中的代码创建的绘制甘特图中提升最大值?

我希望颜色与指数的值“成正比”。

以下是示例代码:

import plotly.figure_factory as ff

df = [dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Complete=10),
      dict(Task="Job B", Start='2008-12-05', Finish='2009-04-15', Complete=60),
      dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Complete=95)]

fig = ff.create_gantt(df, colors='Viridis', index_col='Complete', show_colorbar=True)
fig.show()

需要明确的是:在我的例子中,变量完成可以达到高达700000的值

共有1个答案

卫子平
2023-03-14

根据文档,当给定数字索引时,它应该缩放。然而,看看代码,似乎最小/最大值已硬编码为0和100。见代码行285和286。

一种解决方法是在0-100之间缩放索引并手动将颜色栏的标签设置为原始最小/最大值:

import warnings
warnings.filterwarnings('ignore', category=FutureWarning)  # plotly returns a FutureWarning due to using .ix

from sklearn import preprocessing
import plotly.figure_factory as ff

# create a dataframe for easier processing wrt the scaled index
df = pd.DataFrame([dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28', Complete=10),
      dict(Task="Job B", Start='2008-12-05', Finish='2009-04-15', Complete=60),
      dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30', Complete=995)])

# scale index (0-100) and add as new column
min_max_scaler = preprocessing.MinMaxScaler()
index_scaled = min_max_scaler.fit_transform(df.Complete.values.reshape(-1,1))
df['index_scaled'] = index_scaled * 100

# create figure based on scaled index
fig = ff.create_gantt(df, index_col='index_scaled', colors='Viridis', show_colorbar=True)

# set scale of color bar
fig.data[-1]['marker']['cmin'] = df.Complete.min()
fig.data[-1]['marker']['cmax'] = df.Complete.max()
fig.data[-2]['marker']['cmin'] = df.Complete.min()
fig.data[-2]['marker']['cmax'] = df.Complete.max()

# Due to indexing on the scaled value, the tooltip of the bars shows this values instead of its original.
# You could iterate over them and adjust, but you'll need to match the sorting of fig.data to the sorting of the dataframe.
# fig.data[0].name = original_value

fig.show()

请注意,如上面的注释所述,您可能需要注意条形图的工具提示(显示索引值)。这些也可以手动设置,但您需要将fig.data的顺序与原始数据框的顺序相匹配。

 类似资料:
  • 我正试图使用Kryo库来执行对象的深度复制,但我遇到了一个小问题。我想深度复制一个没有瞬态变量的对象。我知道可以将用于,如下所示: 但是我必须为每个类设置一个新的。我可以从Kryo获得一个默认的,并在那里设置吗?我尝试了类似的解决方案,但它什么也做不到:

  • Symfony 3 [Symfony\Component\DependencyInject\Excema\autowiringFailedExcture] 无法自动连接服务AppBundle\Twig\Base64Extense:参数$storag e的方法__construct()引用接口Vich\UploaderBundle\Stor age\StorageInterface,但不存在这样的服

  • 甘特图用于比较类别之间的数据。此外,它还可用于识别每个过程所花费的时间。 它显示了一段时间内任务值的进展。它在一段时间内广泛用于项目管理和其他类型的变异研究。 除时间维度外,甘特图也采用维度和度量。 例如,使用Sample-Superstore数据源,可以按照每种类型的发运模式进行运输。对于创建,甘特图遵循程序如下: 第1步:转到工作表。 单击“标记(Marks)”窗格中的下拉按钮。 从给定列表中

  • 主要内容:什么是JFreeChart 甘特图,JFreeChart 甘特图的示例什么是JFreeChart 甘特图 甘特图是一种条形图,常用于计划和安排项目任务和事件。 下图显示了 JFreeChart 库中包含的甘特图的一些演示版本: JFreeChart 甘特图的示例 让我们以人口数量作为样本数据。 软件开发阶段 预计日期 实际日期   需求分析 2017-07-03 2017-07-07 2017-07-03 2017-07-05 需求设计 2017-07-10 201

  • 1. 前言 Markdown 的原生语法不支持绘制图形,但通过扩展模块,我们可以将一些格式化的文字渲染成我们需要的图形。常用的图形有 “流程图”、“时序图”、“类图”、“状态图”、“甘特图”、"饼图" 等。 本节将重点介绍如何通过 Mermaid 绘制「甘特图」。 甘特图 (Gantt chart) 也被称为横道图、条状图(Bar chart)。通常用于展示项目进度,它的核心对象是「时间」,并在时

  • 我正在使用Springboot和Java8 我有以下url,它与邮递员配合得很好: "http://localhost:8888/gc/goods/getAll" 现在我尝试编写一个自动测试: 当邮递员给我所有的数据回来,我得到以下错误从我的测试: 组织。springframework。网状物客户ResourceAccessException:获取请求“”时发生I/O错误http://localh