简体   繁体   中英

inaccurate plotly cufflinks plot

I am trying to create plots using cufflinks but they seems to be inaccurate, or to better put it, the y axis doesnt seem to be in order.

the data i am using :

                  time
pos_slot    crane_gkey  
C1   319    85 days 09:29:11
     320    91 days 00:55:00
     329    100 days 21:15:00
     330    47 days 02:00:00
     331    0 days 11:25:00
     333    9 days 13:35:00
     334    3 days 01:15:00
     335    0 days 00:10:00
     336    0 days 05:00:00
     337    0 days 05:00:00
     338    2 days 21:10:00
     339    0 days 12:15:00
     345    9 days 22:50:00
     353    1 days 12:17:28
     362    1 days 08:05:00
     363    0 days 15:50:00
     369    1 days 08:05:00
     406    9 days 20:10:00
     407    12 days 22:05:00
     408    7 days 14:15:00

this goes on for multiple values of pos_slot This is a groupme that i created out of a bigger table. i use the following to create a plot

df1_bct_pos_ctimes3 = df1_bct_pos_ctimes.unstack(level = -2)
df1_bct_pos_ctimes3.iplot(kind = 'scatter')

and i get the following plot 在此处输入图片说明

And as u can see from the data, the plor does not look accurate at all and the y axis seems to be messed up

now if i run the cufflinks on the table without unstacking it and look at C1 for pos_slot i get:

code :

df1_bct_pos_ctimes.iplot(kind = 'scatter')

在此处输入图片说明

and this seems to accurately depict the values in the table.

Also as a side question, how do i customize the axis labels to be more easily understandable?

Thank you.

EDIT : seems like changing time to total seconds fixed the issue. i would still like to know why this issue happened. Thank you.

I tried to recreate the dataframe and a similar error in first plot in the question. In that plot, it appears that the iplot() sees the time column as a string . Therefore the values on y-axis seem to be not as expected. ( Jupyter Notebook 5.0.0, Python 3.6.6 )

Import libraries

import datetime
from datetime import date
from datetime import timedelta
import pandas as pd
import numpy as np
from plotly import __version__
%matplotlib inline

import plotly.offline as pyo
import plotly.graph_objs as go
from plotly.offline import iplot

import cufflinks as cf
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot 
init_notebook_mode(connected=True)

init_notebook_mode(connected=True)
cf.go_offline()

Create sample data

a = [319, 320,329,330,331,333,334,335,336,337,338,339,345,353,362,363,369,406,407,408]
b = ['C1']*len(a)
time = ['85 days 09:29:11', '91 days 00:55:00', '100 days 21:15:00', '47 days 02:00:00',
        '0 days 11:25:00', '9 days 13:35:00', '3 days 01:15:00', '0 days 00:10:00',
        '0 days 05:00:00', '0 days 05:00:00', '2 days 21:10:00', '0 days 12:15:00',
        '9 days 22:50:00', '1 days 12:17:28', '1 days 08:05:00', '0 days 15:50:00',
        '1 days 08:05:00', '9 days 20:10:00', '12 days 22:05:00', '7 days 14:15:00'
       ]

df = pd.DataFrame({'b':b, 'a':a, 'time':time})
df['time'] = df['time'].apply(pd.Timedelta)
df.head(2)

Create a column where time is converted to string

df['str_time'] = str(df.time)
df.dtypes

Create plot: time in string format

(Note: x-axis and y-axis are swtiched as compared to question. Here, the time is now treated as a category. Although, the format is different from the question.)

df[['a', 'str_time']].iplot(kind = 'scatter')

在此处输入图片说明

Create plot: time in datetime format

df[['a', 'time']].iplot(kind = 'scatter')

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM