即使将范围设置为特定时间值,所有时间值也会显示在图形上。该代码段位于下面。
import datetime as dt
import cufflinks as cf
import pandas as pd # dataframe/matrix library
from pandas_summary import DataFrameSummary # nice summaries for pandas dataframes
import numpy as np # matrix math
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot # interactive charts
import plotly.graph_objs as go
import plotly.figure_factory as ff
x = 10;
rng = pd.date_range('1/1/2012', periods=48, freq='H')
time = rng.strftime('%H:%M:%S')
df = pd.DataFrame({ 'Date1': rng, 'Val': x*np.random.randn(len(rng))})
df.set_index('Val')
df['time'] = df['Date1'].dt.time
df['date'] = df['Date1'].dt.date
startTime = df.iloc[5]['time']
endTime = df.iloc[10]['time']
data = [
go.Scatter(
x=df[df['date'] == date]['time'],
y=df[df['date'] == date]['Val'],
name=str(date)
)for date in df.date.unique()]
Layout = go.Layout(title="Test VS Time",xaxis=dict(title='Time',range=[startTime,endTime]),yaxis=dict(title='Value'));
df.iplot(layout=Layout.to_plotly_json(),data=data)
以下图像显示了输出图和数据框。