title: Plotly: How to get defined color bars in Gantt / timeline diagram?
body: <p>I have a plotly <a href="https://plotly.com/python/gantt/" rel="nofollow noreferrer">Gantt / timeline</a> diagram using <code>plotly.express</code> and want to specify the color of my bars as in the <a href="https://plotly.com/python/discrete-color/" rel="nofollow noreferrer">discrete colors</a> tutorial, yet I'm stuck. No matter if <code>color_discrete_map</code> or <code>color_discrete_sequence</code> parameter is used, the output bars are mono-colored:</p>
  <h3>discrete_sequence_resource / same for discrete_sequence_task</h3>
  <p><a href="https://i.stack.imgur.com/zBn4C.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zBn4C.png" alt="discrete_sequence_resource.png" /></a></p>
  <h3>discrete_map_resource / same for discrete_map</h3>
  <p><a href="https://i.stack.imgur.com/Jl8xD.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Jl8xD.png" alt="discrete_map_resource.png" /></a></p>
  <p>As one can see in the pictures above, the bar color is always mono-colored.
  If I just set <code>color=&quot;Resource&quot;</code> the bars are multi-colored accordingly to the resource, which is what I want. Unfortunately, I need to exactly specify the color of the bars due to some later usage.</p>
  <p>Here's the code I used to generate the pictures above:</p>
  <pre class="lang-py prettyprint-override"><code>import pandas as pd
  import plotly.express as px
  from io import StringIO
  import numpy as np
  
  csv = &quot;&quot;&quot;Task,Start,Finish,Workstation,Resource
  1,1970-01-01 01:00:00.000,1970-01-01 01:00:05.400,1,ABL
  2,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,2,ABS
  3,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,3,ABU
  4,1970-01-01 01:00:00.000,1970-01-01 01:00:02.000,4,ACC
  5,1970-01-01 01:00:02.000,1970-01-01 01:00:03.300,4,ACC
  6,1970-01-01 01:00:03.300,1970-01-01 01:00:05.300,4,ACC
  7,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,5,ABS
  8,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,6,ACT
  9,1970-01-01 01:00:00.000,1970-01-01 01:00:02.000,7,ACC
  10,1970-01-01 01:00:02.000,1970-01-01 01:00:03.300,7,ACC
  11,1970-01-01 01:00:03.300,1970-01-01 01:00:05.300,7,ACC
  12,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,8,ABS
  13,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,9,ABU
  14,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,10,ACC
  15,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,11,ABS
  16,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,12,ABU
  17,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,13,ACC
  18,1970-01-01 01:00:01.300,1970-01-01 01:00:03.300,13,ACC
  19,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,14,ABS
  20,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,15,ABP
  21,1970-01-01 01:00:00.000,1970-01-01 01:00:01.500,16,ABZ
  22,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,17,ACC
  23,1970-01-01 01:00:01.300,1970-01-01 01:00:03.300,17,ACC
  24,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,18,ABS
  25,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,19,AAW
  26,1970-01-01 01:00:00.000,1970-01-01 01:00:02.000,20,ACC
  27,1970-01-01 01:00:02.000,1970-01-01 01:00:03.300,20,ACC
  28,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,21,ABS
  29,1970-01-01 01:00:00.000,1970-01-01 01:00:01.000,22,ABU
  30,1970-01-01 01:00:00.000,1970-01-01 01:00:01.300,23,ACC&quot;&quot;&quot;
  
  df = pd.read_csv(StringIO(csv))
  
  
  def rgb(): return 'rgb(' + ','.join(map(str, np.random.randint(0, 255, size=3))) + ')'
  
  discrete_map = { 'ABL': '#0d0887', 'ABS': '#46039f', 'ABU': '#7201a8', 'ACC': '#9c179e', 'ACT': '#bd3786', 'ABP': '#d8576b', 'ABZ': '#ed7953', 'AAW': '#fb9f3a'}
  
  discrete_map_resource = {r: rgb() for r in df.Resource}
  discrete_sequence_resource = [rgb() for resource in df.Resource.unique()]
  discrete_sequence_task = [rgb() for task in df.Task]
  
  fig = px.timeline(df, x_start=&quot;Start&quot;, x_end=&quot;Finish&quot;, y=&quot;Task&quot;, color_discrete_sequence=discrete_sequence_resource, text=&quot;Task&quot;, width=1600, height=800)
  fig.write_image('discrete_sequence_resource.png')
  
  fig = px.timeline(df, x_start=&quot;Start&quot;, x_end=&quot;Finish&quot;, y=&quot;Task&quot;, color_discrete_sequence=discrete_sequence_task, text=&quot;Task&quot;, width=1600, height=800)
  fig.write_image('discrete_sequence_task.png')
  
  fig = px.timeline(df, x_start=&quot;Start&quot;, x_end=&quot;Finish&quot;, y=&quot;Task&quot;, color_discrete_map=discrete_map, text=&quot;Task&quot;, width=1600, height=800)
  fig.write_image('discrete_map.png')
  
  fig = px.timeline(df, x_start=&quot;Start&quot;, x_end=&quot;Finish&quot;, y=&quot;Task&quot;, color_discrete_map=discrete_map_resource, text=&quot;Task&quot;, width=1600, height=800)
  fig.write_image('discrete_map_resource.png')
  </code></pre>
  <p>Additional info (tested with <code>v4.12</code> and <code>v4.13</code>):</p>
  <pre><code>plotly             4.13.0
  </code></pre>