Skip to content
Advertisement

How would I create a bar plot with multiple start and end points on a single date?

I’ve been trying to assist my wife, who is tracking her time per client for a day, by visualising her time spent working each day coloured by clients.

Here is an example of what I’m trying to achieve in Python (constructed in Excel for reference, code contains data of the sample).

enter image description here

JavaScript

Thank you for all the assistance, I hope there might be a simpler solution than making manual Excel graphs.

Advertisement

Answer

I haven’t tried plotting something like this before, so the code could definetely be better. With that said, here’s what I’ve been able to achieve: bar-plot

First, you need to import some packages:

JavaScript

I’ve taken the liberty of removing the header from your data array and converting it to numpy array:

JavaScript

Afterward, we need to get all unique days in a sorted list and make dictionary using this:

JavaScript

Then a colormapping based on the client is made:

JavaScript

As a final setup, we need to save the start and end time for each entry:

JavaScript

Now we can iterate through all data points and add a vertice, color and the text location for that:

JavaScript

When you have this, it’s basic Matplotlib stuff afterwards:

JavaScript

You can view the full code in this Github gist.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement