0

So, I have a problem similar to this question. I have a DataFrame with a column 'diff' and a column 'date' with the following dtypes:

delta_df['diff'].dtype
>>> dtype('<m8[ns]')
delta_df['date'].dtype
>>> datetime64[ns, UTC]

According to this answer, there are (kind of) equivalent. However, then I plot using plotly (I used histogram and scatter), the 'diff' axis has a weird unit. Something like 2T, 2.5T, 3T, etc, what is this? The data on 'diff' column looks like 0 days 00:29:36.000001 so I don't understand what is happening (column of 'date' is 2018-06-11 01:04:25.000005+00:00).

BTW, the diff column was generated using df['date'].diff().

So my question is:

  1. What is this T? Is it a standard choosen by plotly like 30 mins and then 2T is 1 hour? if so, how to check the value of the chosen T?
  2. Maybe more important, how to plot with the axis as it appears on the column so it's easier to read?
J Agustin Barrachina
  • 3,501
  • 1
  • 32
  • 52
  • 1
    Here is the [information](https://plotly.com/python/time-series/#configuring-tick-labels) you need to know when dealing with time series in plotly axes. For example, 1000*60*60*24 represents one day. The configuration entry is dtick='1000*60*60*24'. For the above intervals, please refer to the examples in the references. – r-beginners Feb 16 '23 at 13:45

1 Answers1

1

The "T" you see in the axis label of your plot represents a time unit, and in Plotly, it stands for "Time". By default, Plotly uses seconds as the time unit, but if your data spans more than a few minutes, it will switch to larger time units like minutes (T), hours (H), or days (D). This is probably what is causing the weird units you see in your plot.

It's worth noting that using "T" as a shorthand for minutes is a convention adopted by some developers and libraries because "M" is already used to represent months.

To confirm that the weird units you see are due to Plotly switching to larger time units, you can check the largest value in your 'diff' column. If the largest value is more than a few minutes, Plotly will switch to using larger time units.

Chase
  • 71
  • 7
  • Well it was close enough, the max was `0 days 04:55:35` which stands for 17735 seconds. And my max on the plot was 17.735T... so evidently 1T = 1000 secs. How can I change that? To put the axis in the format I have with `'date'`? – J Agustin Barrachina Feb 16 '23 at 12:53
  • 1
    To change the time unit used by Plotly, you can set the tickformat property of the axis to a format that matches your data. For example, if your time data is in the format of YYYY-MM-DD HH:mm:ss.SSSSSS, you can set the tickformat to "%Y-%m-%d %H:%M:%S.%6f" to display the time with microseconds precision. You can adjust the format to match the format of your date column. – Chase Feb 17 '23 at 10:37