Skip to content

Instantly share code, notes, and snippets.

@amitrani6
Created November 22, 2019 03:50
Show Gist options
  • Save amitrani6/f519f9b855b9199cad19245aee0b824a to your computer and use it in GitHub Desktop.
Save amitrani6/f519f9b855b9199cad19245aee0b824a to your computer and use it in GitHub Desktop.
OHLC with Plotly for the Campbell Soup Company
# 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()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment