Skip to content

Commit cbb7bbf

Browse files
committed
plotly.express, more inlining
1 parent 418eb66 commit cbb7bbf

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

notebooks/time-series.md

+14-13
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ jupyter:
3434
permalink: python/time-series/
3535
thumbnail: thumbnail/time-series.jpg
3636
title: Time Series Plots | plotly
37+
v4upgrade: true
3738
---
3839

3940
### Time Series Plot with `datetime` Objects ###
4041

41-
Time series can be represented using either `plotly_express` functions (`px.line`, `px.scatter`) or `plotly.graph_objs` charts objects (`go.Scatter`). For more examples of such charts, see the documentation of [line and scatter plots](https://plot.ly/python/line-and-scatter/).
42+
Time series can be represented using either `plotly.express` functions (`px.line`, `px.scatter`) or `plotly.graph_objs` charts objects (`go.Scatter`). For more examples of such charts, see the documentation of [line and scatter plots](https://plot.ly/python/line-and-scatter/).
4243

4344
```python
44-
# Using plotly_express
45-
import plotly_express as px
45+
# Using plotly.express
46+
import plotly.express as px
4647

4748
import pandas as pd
4849
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
@@ -86,21 +87,21 @@ import pandas as pd
8687

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

89-
trace_high = go.Scatter(
90+
fig = go.Figure()
91+
fig.add_trace(go.Scatter(
9092
x=df.Date,
9193
y=df['AAPL.High'],
9294
name="AAPL High",
9395
line_color='deepskyblue',
94-
opacity=0.8)
96+
opacity=0.8))
9597

96-
trace_low = go.Scatter(
98+
fig.add_trace(go.Scatter(
9799
x=df.Date,
98100
y=df['AAPL.Low'],
99101
name="AAPL Low",
100102
line_color='dimgray',
101-
opacity=0.8)
103+
opacity=0.8))
102104

103-
fig = go.Figure(data=[trace_high, trace_low])
104105
# Use date string to set xaxis range
105106
fig.update(layout_xaxis_range=['2016-07-01','2016-12-31'],
106107
layout_title_text="Manually Set Date Range")
@@ -115,13 +116,13 @@ import pandas as pd
115116

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

118-
trace_high = go.Scatter(x=df.Date, y=df['AAPL.High'], name="AAPL High",
119-
line_color='deepskyblue')
119+
fig = go.Figure()
120+
fig.add_trace(go.Scatter(x=df.Date, y=df['AAPL.High'], name="AAPL High",
121+
line_color='deepskyblue'))
120122

121-
trace_low = go.Scatter(x=df.Date, y=df['AAPL.Low'], name="AAPL Low",
122-
line_color='dimgray')
123+
fig.add_trace(go.Scatter(x=df.Date, y=df['AAPL.Low'], name="AAPL Low",
124+
line_color='dimgray'))
123125

124-
fig = go.Figure(data=[trace_high, trace_low])
125126
fig.update(layout_title_text='Time Series with Rangeslider',
126127
layout_xaxis_rangeslider_visible=True)
127128
fig.show()

0 commit comments

Comments
 (0)