Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7635097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:21:17+00:00 2026-05-31T07:21:17+00:00

I’ve been having some difficulty with Matplotlib’s finance charting. It seems like their candlestick

  • 0

I’ve been having some difficulty with Matplotlib’s finance charting. It seems like their candlestick charts work best with daily data, and I am having a hard time making them work with intraday (every 5 minutes, between 9:30 and 4 pm) data.

I have pasted sample data in pastebin. The top is what I get from the database, and the bottom is tupled with the date formatted into an ordinal float for use in Matplotlib.

Link to sample data

When I draw my charts there are huge gaps in it, the axes suck, and the zoom is equally horrible. https://i.stack.imgur.com/lO35U.jpg

Enter image description here

How do I make a nice readable graph out of this data? My ultimate goal is to get a chart that looks remotely like this:

Enter image description here

https://i.stack.imgur.com/gawAl.png

The data points can be in various increments from 5 minutes to 30 minutes.


I have also made a Pandas dataframe of the data, but I am not sure if pandas has candlestick functionality.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T07:21:19+00:00Added an answer on May 31, 2026 at 7:21 am

    If I understand well, one of your major concern is the gaps between the daily data.
    To get rid of them, one method is to artificially ‘evenly space’ your data (but of course you will loose any temporal indication intra-day).

    Anyways, doing this way, you will be able to obtain a chart that looks like the one you have proposed as an example.

    The commented code and the resulting graph are below.

    import numpy as np
    import matplotlib.pyplot as plt
    import datetime
    
    from matplotlib.finance import candlestick
    from matplotlib.dates import num2date
    
    # data in a text file, 5 columns: time, opening, close, high, low
    # note that I'm using the time you formated into an ordinal float
    data = np.loadtxt('finance-data.txt', delimiter=',')
    
    # determine number of days and create a list of those days
    ndays = np.unique(np.trunc(data[:,0]), return_index=True)
    xdays =  []
    for n in np.arange(len(ndays[0])):
        xdays.append(datetime.date.isoformat(num2date(data[ndays[1],0][n])))
    
    # creation of new data by replacing the time array with equally spaced values.
    # this will allow to remove the gap between the days, when plotting the data
    data2 = np.hstack([np.arange(data[:,0].size)[:, np.newaxis], data[:,1:]])
    
    # plot the data
    fig = plt.figure(figsize=(10, 5))
    ax = fig.add_axes([0.1, 0.2, 0.85, 0.7])
        # customization of the axis
    ax.spines['right'].set_color('none')
    ax.spines['top'].set_color('none')
    ax.xaxis.set_ticks_position('bottom')
    ax.yaxis.set_ticks_position('left')
    ax.tick_params(axis='both', direction='out', width=2, length=8,
                   labelsize=12, pad=8)
    ax.spines['left'].set_linewidth(2)
    ax.spines['bottom'].set_linewidth(2)
        # set the ticks of the x axis only when starting a new day
    ax.set_xticks(data2[ndays[1],0])
    ax.set_xticklabels(xdays, rotation=45, horizontalalignment='right')
    
    ax.set_ylabel('Quote ($)', size=20)
    ax.set_ylim([177, 196])
    
    candlestick(ax, data2, width=0.5, colorup='g', colordown='r')
    
    plt.show()
    

    graph

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
I have a jquery bug and I've been looking for hours now, I can't
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I've got a string that has curly quotes in it. I'd like to replace
I would like to run a str_replace or preg_replace which looks for certain words
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.