Skip to content
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

Improve plotting Timedelta on y-axis (Timedelta string representation) #17553

Open
s-celles opened this issue Sep 15, 2017 · 6 comments
Open

Comments

@s-celles
Copy link
Contributor

s-celles commented Sep 15, 2017

Code Sample, a copy-pastable example if possible

Following #9154 (comment) and #16953 (comment)

import pandas as pd
from pandas.compat import StringIO
import matplotlib.pyplot as plt


dat = """c1,c2,c3
1000,2000,1500
9000,8000,1600"""

df = pd.read_csv(StringIO(dat))

#print(df)

#df.plot.bar()
#plt.show()

df = df.apply(lambda x: pd.to_timedelta(x, unit='ms'))

print(df)

df.plot.bar()
plt.show()

Displays

        c1       c2              c3
0 00:00:01 00:00:02 00:00:01.500000
1 00:00:09 00:00:08 00:00:01.600000

figure_1-1

Problem description

Y-axis should display Timedelta string representation (not integer values)

Expected Output

Output of pd.show_versions()

[paste the output of pd.show_versions() here below this line]

pd.show_versions()

INSTALLED VERSIONS

commit: 328c7e1
python: 3.6.2.final.0
python-bits: 64
OS: Darwin
OS-release: 16.7.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: fr_FR.UTF-8
LOCALE: fr_FR.UTF-8

pandas: 0.21.0.dev+464.g328c7e179
pytest: 3.2.1
pip: 9.0.1
setuptools: 36.4.0
Cython: 0.26
numpy: 1.13.1
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.2
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.0.2
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: None
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@s-celles
Copy link
Contributor Author

s-celles commented Sep 15, 2017

PR #17430
fixed only partially #16953

@s-celles s-celles changed the title Plotting Timedelta on y-axis Plotting Timedelta on y-axis (Timedelta string representation) Sep 15, 2017
@gfyoung gfyoung added the Visualization plotting label Sep 15, 2017
@s-celles s-celles changed the title Plotting Timedelta on y-axis (Timedelta string representation) Improve plotting Timedelta on y-axis (Timedelta string representation) Sep 16, 2017
@jorisvandenbossche
Copy link
Member

Thanks for opening the issue. So it was actually PR #15067 (issue #8711) that added custom axis label formatting for timedelta, but only for x-axis.
I think the way forward is to add a new TimedeltaConverter and register this with matplotlib.

@1kastner
Copy link

1kastner commented Aug 2, 2018

That sounds great (if that is still current)?

@StefanBrand
Copy link

Timedelta on y-axis still plots as milliseconds. 😬

@bzhphilou78
Copy link

Is there today a solution or a workaround in order to have better data visualization ?

@1kastner
Copy link

1kastner commented Jul 9, 2021

@bzhphilou78 there are two workarounds:

  1. Convert the timedelta into a floating point number of a given time unit, e.g. seconds/minutes/hours, depending on your problem. Just plot that.
  2. Convert the pandas timedelta the numpy correspondent which is natively supported by matplotlib. Then you can use the different formatters that are shipped with matplotlib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants