Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python candlestick chart

# check source link for more details

import plotly.graph_objects as go
import pandas as pd
from datetime import datetime
df = pd.read_csv('https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv')
fig = go.Figure(data=[go.Candlestick(x=df['Date'],
                open=df['AAPL.Open'],
                high=df['AAPL.High'],
                low=df['AAPL.Low'],
                close=df['AAPL.Close'])])

fig.show()
Comment

candlesticks python

# figure size
plt.figure(num=None, figsize=(11, 8), dpi=80, facecolor='w', edgecolor='k')

# "up" dataframe will store the stock_prices when the closing stock price is 
# greater than or equal to the opening stock prices
up = stock_prices[stock_prices.close >= stock_prices.open]
  
# "down" dataframe will store the stock_prices
# when the closing stock price is
# lesser than the opening stock prices
down = stock_prices[stock_prices.close < stock_prices.open]
  
# When the stock prices have decreased, then it
# will be represented by blue color candlestick
col1 = 'g'
  
# When the stock prices have increased, then it 
# will be represented by green color candlestick
col2 = 'r'
  
# Setting width of candlestick elements
width = .3
width2 = .03
  
# Plotting up prices of the stock
plt.bar(up.index, up.close-up.open, width, bottom=up.open, color=col1)
plt.bar(up.index, up.high-up.close, width2, bottom=up.close, color=col1)
plt.bar(up.index, up.low-up.open, width2, bottom=up.open, color=col1)
  
# Plotting down prices of the stock
plt.bar(down.index, down.close-down.open, width, bottom=down.open, color=col2)
plt.bar(down.index, down.high-down.open, width2, bottom=down.open, color=col2)
plt.bar(down.index, down.low-down.close, width2, bottom=down.close, color=col2)

# Grids
plt.minorticks_on()
plt.grid(which='major', color='black', ls = '-', lw = 0.5)
plt.grid(which='minor', color='blue', ls = '-', lw = 0.30) 

# rotating the x-axis tick labels at 30degree 
# towards right
plt.xticks(rotation=30, ha='right')
  
# displaying candlestick chart of stock data 
plt.show()
Comment

PREVIOUS NEXT
Code Example
Python :: how to fill nan values with mean in pandas 
Python :: instagram private account hacking code python 
Python :: order dictionary by value python 
Python :: find first date python 
Python :: how to rename columns in python 
Python :: Delete the node at a given position 2 in a linked list and return a reference to the head node. The head is at position 0. The list may be empty after you delete the node. In that case, return a null value. 
Python :: decrease hours in datetime python 
Python :: django get or 404 
Python :: discord py get user by id 
Python :: python get methods of object 
Python :: how to separate a string or int with comma in python 
Python :: set python 3 as default ubuntu 
Python :: numpy get index of n largest values 
Python :: python program to find factorial 
Python :: discord.py how to use permissions 
Python :: unlimited keyword arguments python 
Python :: python emojis 
Python :: using while loop in python taking input until it matches the desired answer 
Python :: blank=True 
Python :: python sqlite dict 
Python :: create python file kali linux 
Python :: python mysqldb 
Python :: how to send emails in python 
Python :: length of a matrix in python 
Python :: map object to array python 
Python :: python csv 
Python :: plt change grid color 
Python :: python code to remove file extension 
Python :: tuple slicing in python 
Python :: python print combinations of string 
ADD CONTENT
Topic
Content
Source link
Name
2+3 =