Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 problem in plotting intraday results using matplotlib
Hi All,

I try to plot the intraday price for a certain stock.
I have a problem to set the x-axis results. I highlighted the line that cause a problem in comment below.
If I comment this line of code , the program works well but the x-axis has wrong values.
My target is to plot the results and have the x-axis to show the hour-min-sec.

import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as mticker
from mpl_finance import candlestick_ohlc
import json
import urllib

import datetime

def graph_data(stock):

    fig = plt.figure()
    ax1 = plt.subplot2grid((1,1), (0,0))
    myURL = ""+stock+"?symbol="+stock+"&interval=5m"
    with urllib.request.urlopen(myURL) as url:
        data = json.loads(

    x = 0
    y = len(data['chart']['result'][0]['timestamp'])
    ohlc = []

    while x < y:
        append_me = x, data['chart']['result'][0]['indicators']['quote'][0]['open'][x], data['chart']['result'][0]['indicators']['quote'][0]['high'][x], data['chart']['result'][0]['indicators']['quote'][0]['low'][x], data['chart']['result'][0]['indicators']['quote'][0]['close'][x], data['chart']['result'][0]['indicators']['quote'][0]['volume'][x]

    candlestick_ohlc(ax1, ohlc, width=0.4, colorup='green', colordown='red')

    for label in ax1.xaxis.get_ticklabels():
    ax1.xaxis.set_major_formatter(mdates.DateFormatter('%Y-%m-%d %H:%M:%S')) # Problem exists in this line

    plt.subplots_adjust(left=0.09, bottom=0.20, right=0.94, top=0.90, wspace=0.2, hspace=0)


Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  How to append one function1 results to function2 results SriRajesh 5 197 Jan-02-2020, 12:11 PM
Last Post: Killertjuh
  plotting problem TDW5 1 142 Nov-01-2019, 04:54 PM
Last Post: Larz60+
  Matplotlib problem ift38375 0 294 Jul-02-2019, 02:55 PM
Last Post: ift38375
  Matplotlib animation problem Potatoez 1 557 May-21-2019, 03:58 PM
Last Post: Potatoez
  Problem installing numpy and matplotlib achondrite 1 671 Jan-16-2019, 11:43 PM
Last Post: snippsat
  Stack problem, repeating results that i dont want YapYL 1 884 Dec-10-2017, 04:14 PM
Last Post: hshivaraj

Forum Jump:

Users browsing this thread: 1 Guest(s)