Black Lives Matter. Please consider donating to Black Girls Code today.

Plot a candlestick-graph getting data from database using python

Hey there! i was looking all around the internet for a problem in plottng a candlestick-graph from database using python this is the code, can anyone help me because im still unable to figure it out

import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
import numpy as np
from mpl_finance import candlestick_ohlc 
import MySQLdb

db = MySQLdb.connect(host="localhost", user="root", passwd="root", db="toroi")
cur=db.cursor()
cur.execute('SELECT DATE,CLOSE FROM btc_csv')
fig=plt.figure()
graph=fig.set_facecolor('white')
alch_N=[]
alch_m=[]
alch_p=[]
alch_c=[]
alch_d=[]
alch_a=[]
for row in cur.fetchall():
   DATE=str(row[0])

    print("the total data is ",row)
    CLOSE=str(row[1])

    print("the total data is “,row)

    HIGH=str(row[3])
    print("the total data is “,row)

    LOW=str(row[4])
     print("the total data is “,row)

    CLOSE=str(row[5])
    print("the total data is “,row)

    ADJ_CLOSE=str(row[6])
    print("the total data is “,row)

alch_N.append(DATE)
alch_m.append(OPEN)
alch_p.append(HIGH)
alch_c.append(LOW)  
alch_d.append(CLOSE)
alch_a.append(ADJ_CLOSE)

ohlc= db[['Date', 'Open', 'High', 'Low','Close']].copy()
f1, ax = plt.subplots(figsize = (10,5))
candlestick_ohlc(ax, ohlc.values, width=.6, colorup='green', colordown='red')
ax.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m'))
plt.savefig('OHLC FORD.png')
plt.show()

cur.close()
db.close()

Hi @benseshi,

This question doesn’t seem to involve plotly.py, so you probably won’t have much luck in this forum. If you can turn this into a MCVE, Stack Overflow might be a good option.

Good luck,
-Jon

Thankyou @jmmease I will try Ur suggestion