Skip to content

Latest commit

 

History

History
69 lines (44 loc) · 2.06 KB

Plotly_Create_Linechart.md

File metadata and controls

69 lines (44 loc) · 2.06 KB



Template request | Bug report | Generate Data Product

Tags: #plotly #chart #linechart #trend #dataviz #yahoofinance #naas_drivers #snippet #operations #image #html

Author: Jeremy Ravenel

Description: This notebook provides instructions on how to create a line chart using Plotly.

Input

Import libraries

import naas
from naas_drivers import yahoofinance, plotly

Variables

title = "Linechart"

# Output paths
output_image = f"{title}.png"
output_html = f"{title}.html"

Get data

date_from = -360  # Date can be number or date or today
date_to = "today"
df = yahoofinance.get("TSLA", date_from=date_from, date_to=date_to)
df

Model

fig = plotly.linechart(
    df, x="Date", y=["Open", "Close"], title=title, yaxis_title="Price in $"
)

Output

Export in PNG and HTML

fig.write_image(output_image, width=1200)
fig.write_html(output_html)

Generate shareable assets

link_image = naas.asset.add(output_image)
link_html = naas.asset.add(output_html, {"inline": True})

# -> Uncomment the line below to remove your assets
# naas.asset.delete(output_image)
# naas.asset.delete(output_html)