0

I need the option to deselect multiple timeline (jobs) on y-axis so that they are hidden. For example following sample code.


import plotly.express as px
import pandas as pd

df = pd.DataFrame([
    dict(Task="Job A", Start='2009-01-01', Finish='2009-02-28'),
    dict(Task="Job B", Start='2009-03-05', Finish='2009-04-15'),
    dict(Task="Job C", Start='2009-02-20', Finish='2009-05-30')
])

fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task")
fig.update_yaxes(autorange="reversed") # otherwise tasks are listed from the bottom up
fig.show()

Gives this plot enter image description here

I need to option to deselect one or more y-axis Job A/B/C so that they are hidden?

I Found following similar question. But it divides y-axis into categories, instead of selectable options. Y-axis doesn't fit the number of timelines

Faisal
  • 159
  • 1
  • 1
  • 13
  • Does hiding the labels on the y-axis accomplish your objective? To hide them, you can use the following. `fig.update_yaxes(autorange="reversed", tickvals=[1,2,3], ticktext=['','',''])` – r-beginners May 23 '22 at 13:26
  • @r-beginners No, I need to hide any given Jobs timeline (purple bar) out of the available 3. Not hide the labels. – Faisal May 24 '22 at 04:43
  • You can hide it by clicking on the legend to hide it in the user selection. What triggers the display after it has been hidden on the system side? It may be possible to add a button to hide the display. – r-beginners May 24 '22 at 06:42
  • Clicking on legend hides all jobs which have same color. For example here it will hide all 3 jobs. I need to hide 1 or 2 jobs and keep others visible. For my use case I cannot choose different colors for all jobs. – Faisal May 25 '22 at 01:04
  • Check the second example in the [official reference](https://plotly.com/python/gantt/). Adding a resource name to a task adds the resource name to the legend. You can control the visibility of the legend by clicking on the resource name. – r-beginners May 25 '22 at 01:45
  • Thanks for the info. My problem is multiple resources can be present for one job and resources can be shared between jobs. So hiding one resource in legend will also remove it from another job. Where as I just want to hide a job regardless of the resource(s). – Faisal May 25 '22 at 03:48
  • 1
    Try this: `fig = px.timeline(df, x_start="Start", x_end="Finish", y="Task", color="Task")` – r-beginners May 25 '22 at 04:29
  • Yes, that somewhat solves it, though now all my resources within same task have same color and same resource has different color in different task. – Faisal May 25 '22 at 04:38
  • I think that is all the functionality plotly can offer at present. – r-beginners May 25 '22 at 08:20

0 Answers0