-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
No index labels on Dataframe plot with TimedeltaIndex #18910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
How is
|
Could you reproduce it using the dataframe as is? Does it mean that it is malformed somehow? I am using this to generate the indexes:
|
For the sake of those of needs a (quick and dirty) solution till this gets fixed: import pandas
df = pandas.read_pickle("pd_example")
df.plot()
timeunit = 'us' # assuming it is given in micro-seconds
fig = plt.gcf()
ax_ = plt.gca()
labels = ax_.get_xticks().tolist()
new_labels = pd.to_timedelta(labels, unit=timeunit, box=True)
ax_.set_xticklabels(new_labels );
fig.autofmt_xdate() |
As a (non equivalent) alternative [based on this post]: import matplotlib, datetime
from matplotlib import pyplot as plt
def timeTicks(x, pos):
d = datetime.timedelta(microseconds=x)
return str(d)
import pandas as pd
df = pd.read_pickle("pd_example")
ax = df.plot()
formatter = matplotlib.ticker.FuncFormatter(timeTicks)
ax.xaxis.set_major_formatter(formatter)
plt.gcf().autofmt_xdate() |
Easier reproducible example:
and with that I can confirm the regression. If you increase the resolution from 1e-4 to 1e-2 (so > milliseconds), then it works correctly. I suppose this is related to the refactor of timedelta plot xlabel formatting that was done in 0.20 (#15067) |
I must add that the whole timdelta index plotting is broken
|
Code Sample, a copy-pastable example if possible
Download the pickled Example Dataframe, which are basically two sine waves. Then just try to plot it:
Problem description
There are no labels at all for the index (x-axis).
Expected Output
A while ago I had labels as "0 days 00:00:xxx.xxxxx", but it is not the case anymore.
Tested on a fresh installation with same results as I have now (no labels).
Output of
pd.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Windows
OS-release: 10
machine: AMD64
processor: Intel64 Family 6 Model 158 Stepping 9, GenuineIntel
byteorder: little
LC_ALL: None
LANG: None
LOCALE: None.None
pandas: 0.21.1
pytest: 3.3.2.dev44+gdb4df583
pip: 9.0.1
setuptools: 38.2.4
Cython: None
numpy: 1.13.3
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.1
openpyxl: 1.7.0
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: 1.0.1
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
The text was updated successfully, but these errors were encountered: