tikzplotlib
tikzplotlib copied to clipboard
Problems with plotting DatetimeIndex
For the code
import pandas as pd
import tikzplotlib
date_rng = pd.date_range(start='2018-01-01', end='2018-12-01', freq='MS')
df = pd.DataFrame(np.random.randint(0, 100, size=(len(date_rng))), index=date_rng)
fig, ax = plt.subplots(figsize=(10, 4))
ax.plot(df)
ax.set_xticks(pd.DatetimeIndex(['2018-{}-01'.format(month) for month in range(1, 12, 2)]))
ax.grid(linestyle='dotted', which='both')
ax.set_xlim(left=pd.Timestamp('2018-01-01'), right=pd.Timestamp('2019-01-01'))
tikzplotlib.save('plot.tex')
matplotlib plots a wonderful graphic:

However, using tikzplotlib does not result in the same output:

How can I make the DatetimeIndex work?
tex.zip contains the tex-files
I'm having the exact same problem, here's a reproducible example
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import tikzplotlib as tpl
pd.plotting.register_matplotlib_converters()
df = pd.read_csv("https://raw.githubusercontent.com/wcota/covid19br/master/cases-brazil-states.csv")
df['date'] = pd.to_datetime(df['date'])
data_BR = df.query("state == 'TOTAL'")[['date', 'deaths']][22:97]
sns.lineplot(data=data_BR, x='date', y='deaths')
tpl.save("teste.tex", standalone = True)
Gives
