Python: Plot discontinuous data - does brokenaxis package work also for pandas datetime?

Viewed 81

I am trying to plot a discontinuous timeseries with the package brokenaxis by ben.ditcher. However, I can't find a way to make the plot work with pandas datetime timeseries. The error message I get is:

TypeError: unsupported operand type(s) for -: 'str' and 'str'

Since I am rather new to python, I am not sure if there's something I am doing wrong or if it is just that the package is not compatible with pd.datetime. I'd be glad if someone could help me out here.

Here's my attempt of a minimal example:

# import packages    
import matplotlib.pyplot as plt
from brokenaxes import brokenaxes
import pandas as pd
import numpy as np
import random

# generate dataframe with datetime column
dti = pd.date_range('2019-01-01', periods=365, freq='D') # create list with daily datetime objects for the year 2019
random_numbers = random.sample(range(1, 500), 356) # generate 365 random numbers within range 1 to 500
data_tuples = list(zip(dti,random_numbers)) # put lists together
df = pd.DataFrame(data_tuples, columns=['Date','Value']) # create dataframe from lists

# use brokenaxes
fig = plt.figure(figsize=(5,2))
bax = brokenaxes(xlims=(('2019-01-01','2019-02-01'), ('2019-05-01','2019-09-01')),hspace=0.05)

bax.plot(df.Date, df.Value)
0 Answers
Related