question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

No index labels on Dataframe plot with TimedeltaIndex

See original GitHub issue

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:

import pandas
df = pandas.read_pickle("pd_example")
df.plot()

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

Issue Analytics

  • State:open
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
eldad-acommented, Feb 2, 2018

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()

image

0reactions
KKostyacommented, Oct 28, 2019

I must add that the whole timdelta index plotting is broken

td_seconds = pd.to_timedelta([0,1,2,10,11,12], unit="s")
df = pd.DataFrame({'a': np.random.randn(len(td_seconds))}, index=td_seconds)
df.plot(marker='o')
Read more comments on GitHub >

github_iconTop Results From Across the Web

Plotting from a pandas dataframe with a timedelta index
I'm trying to plot some data from a pandas dataframe with a timedelta index and I want to customize the time ticks and...
Read more >
pandas.DataFrame.plot — pandas 0.23.1 documentation
In case subplots=True, share x axis and set some x axis labels to invisible; defaults to True if ax is None otherwise False...
Read more >
Pandas: Create matplotlib plot with x-axis label not index
Pandas : Create matplotlib plot with x-axis label not index. I've been using matplotlib a bit recently, and wanted to share a lesson...
Read more >
[Solved]-Removing days from timedelta index?-Pandas,Python
There's always the option of formatting it as a string, if all you want to do is use it for plotting labels: #...
Read more >
Python Data Science Basics | Kaggle
f,ax = plt.subplots(figsize=(8,8)) data.plot(kind='scatter', x='Speed', y='Defense', ... #dataframe icindeki index ve value'ya ulasma for index,value in ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found