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 8772823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T18:07:46+00:00 2026-06-13T18:07:46+00:00

I’m making a candlestick chart with two data sets: [open, high, low, close] and

  • 0

I’m making a candlestick chart with two data sets: [open, high, low, close] and volume. I’m trying to overlay the volumes at the bottom of the chart like this:

finviz.com

I’m calling volume_overlay3 but instead of bars it fills the whole plot area. What am I doing wrong?

volume_overlay3

My other option is to use .bar(), which doesn’t have the up and down colors but would work if I could get the scale right:

enter image description here

fig = plt.figure()
ax = fig.add_subplot(1,1,1)

candlestick(ax, candlesticks)

ax2 = ax.twinx()

volume_overlay3(ax2, quotes)

ax2.xaxis_date()

ax2.set_xlim(candlesticks[0][0], candlesticks[-1][0])

ax.yaxis.set_label_position("right")
ax.yaxis.tick_right()

ax2.yaxis.set_label_position("left")
ax2.yaxis.tick_left()
  • 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-06-13T18:07:48+00:00Added an answer on June 13, 2026 at 6:07 pm

    The volume_overlay3 did not work for me. So I tried your idea to add a bar plot to the candlestick plot.

    After creating a twin axis for the volume re-position this axis (make it short) and modify the range of the candlestick y-data to avoid collisions.

    import numpy as np
    import matplotlib
    import matplotlib.pyplot as plt
    # from matplotlib.finance import candlestick
    # from matplotlib.finance import volume_overlay3
    # finance module is no longer part of matplotlib
    # see: https://github.com/matplotlib/mpl_finance
    from mpl_finance import candlestick_ochl as candlestick
    from mpl_finance import volume_overlay3
    from matplotlib.dates import num2date
    from matplotlib.dates import date2num
    import matplotlib.mlab as mlab
    import datetime
    
    datafile = 'data.csv'
    r = mlab.csv2rec(datafile, delimiter=';')
    
    # the dates in my example file-set are very sparse (and annoying) change the dates to be sequential
    for i in range(len(r)-1):
        r['date'][i+1] = r['date'][i] + datetime.timedelta(days=1)
    
    candlesticks = zip(date2num(r['date']),r['open'],r['close'],r['max'],r['min'],r['volume'])
    
    fig = plt.figure()
    ax = fig.add_subplot(1,1,1)
    
    ax.set_ylabel('Quote ($)', size=20)
    candlestick(ax, candlesticks,width=1,colorup='g', colordown='r')
    
    # shift y-limits of the candlestick plot so that there is space at the bottom for the volume bar chart
    pad = 0.25
    yl = ax.get_ylim()
    ax.set_ylim(yl[0]-(yl[1]-yl[0])*pad,yl[1])
    
    # create the second axis for the volume bar-plot
    ax2 = ax.twinx()
    
    
    # set the position of ax2 so that it is short (y2=0.32) but otherwise the same size as ax
    ax2.set_position(matplotlib.transforms.Bbox([[0.125,0.1],[0.9,0.32]]))
    
    # get data from candlesticks for a bar plot
    dates = [x[0] for x in candlesticks]
    dates = np.asarray(dates)
    volume = [x[5] for x in candlesticks]
    volume = np.asarray(volume)
    
    # make bar plots and color differently depending on up/down for the day
    pos = r['open']-r['close']<0
    neg = r['open']-r['close']>0
    ax2.bar(dates[pos],volume[pos],color='green',width=1,align='center')
    ax2.bar(dates[neg],volume[neg],color='red',width=1,align='center')
    
    #scale the x-axis tight
    ax2.set_xlim(min(dates),max(dates))
    # the y-ticks for the bar were too dense, keep only every third one
    yticks = ax2.get_yticks()
    ax2.set_yticks(yticks[::3])
    
    ax2.yaxis.set_label_position("right")
    ax2.set_ylabel('Volume', size=20)
    
    # format the x-ticks with a human-readable date. 
    xt = ax.get_xticks()
    new_xticks = [datetime.date.isoformat(num2date(d)) for d in xt]
    ax.set_xticklabels(new_xticks,rotation=45, horizontalalignment='right')
    
    plt.ion()
    plt.show()
    

    plot

    data.csv is up here:
    http://pastebin.com/5dwzUM6e

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
I'm trying to select an H1 element which is the second-child in its group
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka

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.