# Ploting time series data

**URL:** <https://community.plotly.com/t/ploting-time-series-data/5265>\
**Category:** Dash Python\
**Created:** [August 7, 2017, 12:04pm UTC](https://community.plotly.com/t/ploting-time-series-data/5265 "2017-08-07T12:04:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![TomGeo](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@TomGeo](https://community.plotly.com/u/TomGeo)\
**Post date:** [August 7, 2017, 12:04pm UTC](https://community.plotly.com/t/ploting-time-series-data/5265/1 "2017-08-07T12:04:45Z")

</div>

Hi,

I am absolutely fresh with Dash and in the process of converting a Shiny dashboard into one of Dash. While I was using ‘dygraph’ in Shiny I had to find a possibility to do the same in Python. Looking for an example on how to use Plotly to do so I found this [one](https://plot.ly/python/time-series/) where the plotly class is used.

Looking at the examples in the Dash user Guide the graph\_objs class is used, and i was wondering on how I get the example for ‘Time Series With Rangeslider’ from the link above implemented in a Dash-board.

Bests, Thomas

---

<div class="post-metadata">

**Author:** ![chriddyp](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/chriddyp/32/16855_2.png) [@chriddyp](https://community.plotly.com/u/chriddyp)\
**Post date:** [August 7, 2017, 3:53pm UTC](https://community.plotly.com/t/ploting-time-series-data/5265/2 "2017-08-07T15:53:02Z")

</div>

@TomGeo - Awesome!

All of the examples in the Python graphing library construct either a `figure` or `data`.

`figure` is either:

- `figure = {'data': data, 'layout': layout}`
- `figure = go.Figure(data=data, layout=layout)`

In other words, the graphing library and dash accept both `go.*` objects (like `go.Figure`) and just regular `dict` `{}` or lists `[`]`

`figure` is one of the attributes of the `dash_core_components.Graph` component. So, you just need to pass `figure` into the `Graph` component. Here’s an example from the time series link you posted above:

```auto
import plotly.plotly as py
import plotly.graph_objs as go
import dash
import dash_core_components as dcc
import dash_html_components as html

import pandas as pd

df = pd.read_csv("https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv")

trace_high = go.Scatter(
    x=df.Date,
    y=df['AAPL.High'],
    name = "AAPL High",
    line = dict(color = '#17BECF'),
    opacity = 0.8)

trace_low = go.Scatter(
    x=df.Date,
    y=df['AAPL.Low'],
    name = "AAPL Low",
    line = dict(color = '#7F7F7F'),
    opacity = 0.8)

data = [trace_high,trace_low]

layout = dict(
    title='Time Series with Rangeslider',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        rangeslider=dict(),
        type='date'
    )
)

fig = dict(data=data, layout=layout)

# Now here's the Dash part:

dash.layout = html.Div([
    dcc.Graph(id='my-graph', figure=fig)
])

```

---

<div class="post-metadata">

**Author:** ![TomGeo](https://avatars.discourse-cdn.com/v4/letter/t/779978/32.png) [@TomGeo](https://community.plotly.com/u/TomGeo)\
**Post date:** [August 8, 2017, 1:20pm UTC](https://community.plotly.com/t/ploting-time-series-data/5265/3 "2017-08-08T13:20:59Z")

</div>

@chriddyp - awesome, works pretty well!  
Thanks a lot for the prompt help. 😄

---

<div class="post-metadata">

**Author:** ![Monisha\_1709](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/monisha_1709/32/14824_2.png) [@Monisha\_1709](https://community.plotly.com/u/Monisha_1709)\
**Post date:** [April 8, 2021, 2:02pm UTC](https://community.plotly.com/t/ploting-time-series-data/5265/4 "2021-04-08T14:02:35Z")

</div>

Hello Team,

I tried replicating for the same code for a time series data set with 6 columns along with an index columns of DateTime.

```auto
import plotly.plotly as py
import plotly.graph_objs as go
import dash
import dash_core_components as dcc
import dash_html_components as html

import pandas as pd

df = pd.read_csv('test_data.csv', index_col=0, parse_dates=True).fillna(value = 0)
df.index = pd.to_datetime(df.index)

trace1 = go.scatter(x=df.index, y=df[('BAD1-E7-5 -B500 -ME1')], name='BAD1-E7-5 -B500 -ME1')
trace2 = go.scatter(x=df.index, y=df[('BAD1-E7-5 -B500 -ME2')], name='BAD1-E7-5 -B500 -ME2')
trace3 = go.scatter(x=df.index, y=df[('BAD1-E7-5 -B500 -ME3')], name='BAD1-E7-5 -B500 -ME3')
trace4 = go.scatter(x=df.index, y=df[('BAD1-E7-5 -B500 -ME4')], name='BAD1-E7-5 -B500 -ME4')
trace5 = go.scatter(x=df.index, y=df[('BAD1-E7-5 -B500 -ME5')], name='BAD1-E7-5 -B500 -ME5')
trace6 = go.scatter(x=df.index, y=df[('BAD1-E7-5 -B501 -ME1')], name='BAD1-E7-5 -B501 -ME1')

data = [trace1,trace2,trace3,trace4,trace5,trace6]

layout = dict(
    title='Time Series of sensor df_n_light with Rangeslider',
    xaxis=dict(
        rangeselector=dict(
            buttons=list([
                dict(count=1,
                     label='1m',
                     step='month',
                     stepmode='backward'),
                dict(count=6,
                     label='6m',
                     step='month',
                     stepmode='backward'),
                dict(step='all')
            ])
        ),
        rangeslider=dict(),
        type='date'
    )
)

fig = dict(data=data, layout=layout)

# Now here's the Dash part:

dash.layout = html.Div([
    dcc.Graph(id='my-graph', figure=fig)
])

```

I am getting an error with this code, could you please guide me why i am getting the below error message?

> Traceback (most recent call last):
> 
> File “C:\Users\Monisha\Desktop\dash\_sensor.py”, line 7, in   
> import plotly.plotly as py
> 
> File “C:\Users\Monisha\anaconda3\lib\site-packages\plotly\plotly\__init_\_.py”, line 4, in   
> \_chart\_studio\_error(“plotly”)
> 
> File “C:\Users\Monisha\anaconda3\lib\site-packages\_plotly\_future\_\__init_\_.py”, line 43, in \_chart\_studio\_error  
> raise ImportError(
> 
> ImportError:  
> The plotly.plotly module is deprecated,  
> please install the chart-studio package and use the  
> chart\_studio.plotly module instead.
> 
> ![image](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/e/e03be00cdff6ebdbd2dc20436fcc054922284640.png)
