tikzplotlib icon indicating copy to clipboard operation
tikzplotlib copied to clipboard

Problems with plotting DatetimeIndex

Open michaeldorner opened this issue 6 years ago • 1 comments

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:

Unknown

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

Bildschirmfoto 2020-02-09 um 17 58 20

How can I make the DatetimeIndex work?

tex.zip contains the tex-files

michaeldorner avatar Feb 09 '20 17:02 michaeldorner

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

test-1

August0Andrade avatar Mar 19 '21 12:03 August0Andrade