Nicole Suter
Nicole Suter

Reputation: 99

Recreate this chart in python - what type of chart is it?

I'm trying to recreate the chart from this post on Reddit. How would I recreate a chart like this in python? What would you even call this type of chart?

The chart looks like this:

enter image description here

I tried this similar approach, but a bubble chart isn't quite what I'm looking for. Here's a simplified version of my data:

Date,Asleep,Awake
3/31,12:00 AM,5:00 AM
3/31,6:00 AM,8:30 AM
3/31,12:00 PM,2:45 PM
3/31,5:30 PM,8:30 PM
3/31,11:00 PM,11:59 PM
4/1,12:00 AM,4:30 AM
4/1,6:00 AM,9:00 AM
4/1,11:30 AM,2:00 PM
4/1,5:00 PM,9:00 PM
4/1,10:45 PM,11:59 PM
4/2,12:00 AM,2:30 AM
4/2,3:00 AM,8:00 AM
4/2,10:30 AM,2:00 PM
4/2,5:00 PM,10:00 PM
4/3,12:00 AM,8:30 AM
4/3,11:00 AM,3:00 PM
4/3,6:00 PM,9:00 PM
4/3,10:30 PM,11:59 PM
4/4,12:00 AM,9:00 AM
4/4,10:30 AM,12:00 PM
4/4,3:30 PM,5:00 PM
4/4,8:00 PM,10:30 PM
4/4,11:00 PM,11:59 PM

Upvotes: 3

Views: 82

Answers (1)

piRSquared
piRSquared

Reputation: 294258

This gets you part of the way...

Convert to proper types

df['Date'] = pd.to_datetime(df.Date.radd('2020/'), format='%Y/%m/%d')
df['Asleep'] = pd.to_datetime(df.Asleep) - pd.Timestamp('now').normalize()
df['Awake'] = pd.to_datetime(df.Awake) - pd.Timestamp('now').normalize()

vlines

import matplotlib.pyplot as plt

plt.vlines(df.Date, df.Asleep, df.Awake)

From here, you need to figure out how to format the axes and thicken the lines. That's more matplotlib than I want to deal with this morning.

enter image description here

Upvotes: 2

Related Questions