理解 Plotly 的时间差单位

huangapple go评论111阅读模式
英文:

Understanding Plotly Time Difference units

问题

我有一个类似于这个问题的问题。我有一个DataFrame,其中包含一个名为'diff'的列和一个名为'date'的列,它们的数据类型如下:

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

根据这个答案,它们在某种程度上是等价的。然而,当我使用plotly绘图时(我使用了直方图和散点图),'diff'轴上出现了奇怪的单位,类似于2T, 2.5T, 3T等等,这是什么意思?'diff'列上的数据看起来像0 days 00:29:36.000001,所以我不明白发生了什么('date'列的数据是2018-06-11 01:04:25.000005+00:00`)。

顺便说一下,diff列是使用df['date'].diff()生成的。

所以我的问题是:

  1. 这个T是什么?它是由plotly选择的标准吗,比如30分钟,然后2T是1小时?如果是的话,如何检查所选择的T的值?
  2. 可能更重要的是,如何绘制轴,以便它与列中显示的内容一致,以便更容易阅读?
英文:

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

delta_df[&#39;diff&#39;].dtype
&gt;&gt;&gt; dtype(&#39;&lt;m8[ns]&#39;)
delta_df[&#39;date&#39;].dtype
&gt;&gt;&gt; datetime64[ns, UTC]

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

BTW, the diff column was generated using df[&#39;date&#39;].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?

答案1

得分: 1

"T" 在你的图表坐标标签中表示时间单位,在Plotly中它代表"Time"。默认情况下,Plotly使用秒作为时间单位,但如果你的数据跨越了几分钟以上的时间,它会切换到更大的时间单位,如分钟(T)、小时(H)或天(D)。这很可能是导致你在图表中看到奇怪时间单位的原因。

值得注意的是,使用"T" 作为分钟的简写是一种由一些开发者和库采纳的惯例,因为"M" 已经用来表示月份。

要确认你看到的奇怪时间单位是由于Plotly切换到更大的时间单位,你可以检查你的'diff'列中的最大值。如果最大值超过了几分钟,Plotly将切换到使用更大的时间单位。

英文:

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.

huangapple
  • 本文由 发表于 2023年2月16日 19:46:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75471806.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定