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.

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

See original GitHub issue

Code Sample, a copy-pastable example if possible

Following https://github.com/pandas-dev/pandas/issues/9154#issuecomment-329814404 and https://github.com/pandas-dev/pandas/issues/16953#issuecomment-329905621

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: 328c7e179b72e257e27adf92a06718fd5a40473f 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

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
1kastnercommented, 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.
2reactions
StefanBrandcommented, May 19, 2020

Timedelta on y-axis still plots as milliseconds. 😬

Read more comments on GitHub >

github_iconTop Results From Across the Web

Plot datetime.timedelta using matplotlib and python
I am working on a task, where I need to calculate time spent on each day and then represent that time ...
Read more >
Matplotlib Tutorial — 8 - Medium
Here, we have imported pandas, DateTime,timedelta, and dates from matplotlib. ... That provides, our x-axis date for better representation.
Read more >
Better matplotlib charts - Christopher Flynn, PhD
I do a lot of analysis of time series data and more often than not plotting that data means that the x-axis values...
Read more >
Graph Plotting in Python | Set 1 - GeeksforGeeks
To set the x-axis values, we use the np.arange() method in which the first two arguments are for range and the third one...
Read more >
What's New — pandas 0.23.0 documentation - PyData |
Categorical; Datetimelike; Timedelta; Timezones; Offsets; Numeric; Strings; Indexing; MultiIndex; I/O; Plotting; Groupby/Resample/Rolling; Sparse; Reshaping ...
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