Skip to content

Latest commit

 

History

History
97 lines (70 loc) · 2.53 KB

Plotly_Create_Candlestick.md

File metadata and controls

97 lines (70 loc) · 2.53 KB



Template request | Bug report | Generate Data Product

Tags: #plotly #chart #candlestick #group #dataviz #snippet #operations #image #html

Author: Jeremy Ravenel

Description: This notebook provides an example of how to create a candlestick chart using the Plotly library.

Input

Import libraries

import naas
from naas_drivers import yahoofinance
import plotly.graph_objects as go
import pandas as pd

Variables

title = "Candlestick"

# 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

Create Candlestick

fig = go.Figure()
fig = go.Figure(
    data=[
        go.Candlestick(
            x=df["Date"],
            open=df["Open"],
            high=df["High"],
            low=df["Low"],
            close=df["Close"],
        )
    ]
)

fig.update_layout(
    title=title,
    plot_bgcolor="#ffffff",
    width=1200,
    height=800,
    xaxis_tickfont_size=14,
    yaxis=dict(
        title="Price in $",
        titlefont_size=16,
        tickfont_size=14,
    ),
)
config = {"displayModeBar": False}
fig.show(config=config)

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)