1

So I've been through stack overflow and have used solutions from other posts. But no matter what I try my ticks always remain as just ints and don't adopt the datetime format i yearn for. Any help would be appreciated!

from datetime import datetime, time
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import ticker
import mpl_finance
import MySQLdb

def isolated_candle_graph():
    #Access my database
    conn = MySQLdb.connect(host='localhost',
                       user='root',
                       passwd='*******',#
                       db='********') # falsified information
    cursor = conn.cursor()
    sql = "SELECT * FROM ddr"
    cursor.execute(sql)
    result = cursor.fetchall()
    df = pd.DataFrame(list(result), columns=["Date", "Open", "High","Low", "Close", "Adj_Close", "Volume"])

    fig, ax = plt.subplots()
    #the plot
    mpl_finance.candlestick2_ohlc(ax, df.Open, df.High, df.Low, df.Close,
                  width=0.6, colorup='r', colordown='c', alpha=1)
    xdate = df.index
    def mydate(x, pos):
        try:
            return xdate[int(x)]
        except IndexError:
            return ''

    ax.xaxis.set_major_formatter(ticker.FuncFormatter(mydate))
    plt.show()
isolated_candle_graph()

Thanks!

This is what I've been following.

matplotlib.finance.candlestick_ohlc plot intraday 1min bar data with time breaks and proper xticklabels at every hour

0 Answers0