0

I'm trying to make a Gantt chart for certain tasks we have to do for every customer.

The idea is generating a plotly.express.timeline for every customer and plotting them in a shared timeline.

When I print the chart, it generates a plot with varying bar sizes, if the customer has a few tasks you can discern between them, but the more tasks it has the harder it is to see clearly.

I've created the following function to plot them:

def generate_gantt_test(self):
        # Process DataFrame
        self.df = map_comments(self.df)
        df = self.filter_values()

        # Create a dict for every customer
        customers = df['Customer'].unique()

        # Create a gantt chart for every customer
        customer_plots = dict()
        for customer in customers:
            customer_plot = df.loc[df['Customer'] == customer]

            fig = px.timeline(customer_plot, x_start='StartDate', x_end='DueDate')
            fig.update_yaxes(showticklabels=False) #Doesn't get rid of y_axes labels?
            fig.update_yaxes(autorange='reversed')
            customer_plots[get_random_string(len(customer))] = fig

        # Plot them in a shared x_axis       
        fig_sub = make_subplots(rows=len(customer_plots), shared_xaxes=True, subplot_titles=list(customer_plots.keys()))
        fig_sub.update_xaxes(type='date')

        for i, (customer, plot) in enumerate(customer_plots.items()):
            fig_sub.append_trace(plot['data'][0], row=i+1, col=1)

        fig_sub.write_image('gantt.png')

And it generates the following result:

enter image description here

For privacy reasons I've randomized the names of the customers.

As you can see, the plot is almost unreadable, text is too big and timelines are too small.

What I want to accomplish is define a fixed bar size so every chart has the same bar size, therefore making the total size of every gantt chart vary depending on the amount of tasks the customer has, and thus increasing the total size of the plot to take as much space as needed to better improve the readability of the chart.

I also want to get rid of the y_axis labels which I thought I could do with:

fig.update_yaxes(showticklabels=False)

Can this be accomplished using plotly.express.timeline or would I have to look at an alternative solution to obtain the desired result mentioned above?

BigBen
  • 46,229
  • 7
  • 24
  • 40

0 Answers0