Skip to content

Instantly share code, notes, and snippets.

@amitrani6
Created November 22, 2019 03:50

Revisions

  1. amitrani6 created this gist Nov 22, 2019.
    29 changes: 29 additions & 0 deletions plotly_ohlc.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    # A Plotly OHLC Chart With A Rangeslider
    # This code is adapted from the Plotly site
    # Source: https://plot.ly/python/ohlc-charts/

    # Import the necessary libraries
    import pandas as pd
    import numpy as np

    # The section of the Plotly library needed
    import plotly.graph_objects as go

    # Obtain data from the data frame
    fig = go.Figure(data=go.Ohlc(x=cpb['Date'],
    open=cpb['Open'],
    high=cpb['High'],
    low=cpb['Low'],
    close=cpb['Close']))

    # Add title and annotations
    fig.update_layout(title_text='CPB From November 21, 2018 to November 21, 2019',
    title={
    'y':0.9,
    'x':0.5,
    'xanchor': 'center',
    'yanchor': 'top'},
    xaxis_rangeslider_visible=True, xaxis_title="Time", yaxis_title="Growth Rate Percentage")


    fig.show()