Create Linechart
Tags: #plotly #chart #linechart #trend #dataviz #yahoofinance #naas_drivers #snippet
Author: Jeremy Ravenel
Learn more on the Plotly doc : https://plotly.com/python/line-charts/

Input

Import libraries

1
import naas
2
from naas_drivers import yahoofinance, plotly
Copied!

Variables

1
title = "Linechart"
2
3
# Output paths
4
output_image = f"{title}.png"
5
output_html = f"{title}.html"
Copied!

Get data

1
date_from = -360 # Date can be number or date or today
2
date_to = "today"
3
df = yahoofinance.get("TSLA",
4
date_from=date_from,
5
date_to=date_to)
6
df
Copied!

Model

1
fig = plotly.linechart(df,
2
x="Date",
3
y=["Open", "Close"],
4
title=title,
5
yaxis_title="Price in quot;)
Copied!

Output

Export in PNG and HTML

1
fig.write_image(output_image, width=1200)
2
fig.write_html(output_html)
Copied!

Generate shareable assets

1
link_image = naas.asset.add(output_image)
2
link_html = naas.asset.add(output_html, {"inline":True})
3
4
#-> Uncomment the line below to remove your assets
5
# naas.asset.delete(output_image)
6
# naas.asset.delete(output_html)
Copied!
Copy link
Edit on GitHub