Related posts

39 Thoughts to “Matplotlib Tutorial 14 – candlestick OHLC graphs”

  1. h3po

    wouldn’t hurt to use “for x,y in enumerate(date)” or at least “for x in range(len(date))” instead of an ugly while loop for the ohlc data. i guess you did that for not to overcomplicate things for beginners, but i think being confronted with pythonic stuff like this will benefit them greatly. for more advanced python programmers, that kind of while loop is just irritating 😉
    anyway, thanks for this relatively quick overview of matplotlib. regarding the styling of labels and such, i learned a few things that i didn’t know about from just browsing the wiki.

    1. Thanh Tung Dao

      do you mind explaining why do we write that line of code? I have trouble following that part

  2. Kaleab Woldemariam

    Thank you Sentdex for your tutorials.I was trying to use a candlestick chart but for some reason the candlesticks are all green. I assume that closep

    1. username

      lol better than mine, mine are black

    2. Yoga Murthy.s

      ax1 = plt.subplot2grid((1,1), (0,0))
      candlestick2_ohlc(ax1,my_file[‘Open’],my_file[‘High’],my_file[‘Low’],my_file[‘Close’],width=0.6,colorup=’#77d879′, colordown=’#db3f3f’)

  3. david196609876

    What is the required format for times rather than dates?

    1. TheShepherd

      +david196609876 %m/%d/%Y %H:%M:%S maps to 05/21/2016 17:12:47

  4. Jean Nassar

    Why not use a zip for creating ohlc? If you need a list instead of a generator, just wrap the whole thing in list() when you’re making it.

    ohlc = zip(date, openp, highp, lowp, closep, volume)

    1. Samuel Muiruri

      didn’t know you could do it this way, neat 🙂

    2. Mike Shun

      just wondering what MaxNLocator literally stands for..

  5. Shako Python

    How would you get rid of the weekend gaps while still keeping dates as x-ticks? So far the only thing I can come up with is make each week its own subplot, which seems inefficient.

    1. chemhong

      How about minutes data? how to remove the lunch gap? thanks sentdex~

    2. soubhagya rout

      I have also the same question. How to remove the lunch gap?

  6. Cope Sledge

    some might get an import error among other issues if you’re using a different version of matplotlib or python. I had to make the following changes…

    remove the “_ohlc”:

    from import candlestick

    change the order of the ohlc data:

    while x < y: append_me = date[x], openp[x], closep[x], highp[x], lowp[x]

  7. mindOVERmatter100000

    Why isn’t the ohlc graph complete. As in whats the reason for the gaps between candlesticks. Is there a way to fill the gaps.

    1. ross

      Late response, but the stock market isn’t open on weekends so data from these dates cannot be graphed, because there is no stock data.

  8. Mounir Hader

    How could i add other stuff to the same plot? Like horizontal/vertical lines at arbitrary positions? it seems i cannot simply do plt.plot(date) after the candlestick_ohlc fucntion is called. thanks!

  9. Saad Ahmed

    I am having this warning message and my graph isnt showing up.

    MatplotlibDeprecationWarning: The finance module has been deprecated in mpl 2.0 and will be removed in mpl 2.2. Please use the module mpl_finance instead.
    warnings.warn(message, mplDeprecation, stacklevel=1)

    Love your tutorial but this yahoo finance api being shutdown or whatever kinda ruins the fun.

    1. Parth Thakur

      It’s a warning that says the finance module will be removed in future updates. I get the same warning, but my charts show up.

    2. Rex Morgan

      Any ideas on what to use as a replacement for the module? I get the ‘No module name ‘” error message.

    3. marrowgar

      you need to install the latest library. simply do the following:
      pip install mpl_finance
      then you can import the finance library using:
      from mpl_finance import candlestick_ohlc

  10. Tomás Enrique Sierra Polanco

    You’re videos are unbelieveble! I think there have been some downs in people who watch them because of the video where you introduce us to internet data… sorry about that. But I can’t stop watching these <3

  11. Kamil Ziemian

    Again, this my by wrongheaded hairsplitting. I think this video title should be “Matplotlib Tutorial 14 – Candlestick OHLC graphs”.

  12. Schrodinger's Cat

    your killin me smalls

  13. Muhib Al Hasan

    If you can’t import matplotlib.finace then go to , download and copy Then go to your python directory>Lib>site-packages>matplotlib and paste it there.

  14. Lizzy Bennet has been depreciated for some time. I installed mpl_finance but I can’t seem to use the module. Is it possible for you to do a video about installing and using mpl_finance?

    1. Ford 44

      If i had trouble with other deprecated libraries is there a central site that i can go to?

    2. Minespidur

      @Алмаз Кошоев I did this, but when I try and run the program nothing happens. I installed mpl_finance

    3. Алмаз Кошоев

      @Minespidur , checked it right now, it still works fine for me. Check your code

    4. Stephen C

      Mpl_finance works ok for me using linux and python 3.6. I used pip to install, “pip install“, then import as normal “from mpl_finance import candlestick_ohlc”

    5. Ajay Kumar

      @Stephen C Thankx Stephen…

  15. Samuel Muiruri

    I found some bitcoin data with the open,close, high and low and decided it was a neat opportunity to graph a candlestick graph. It brings a bunch of errors hoping someone here might know the solution. Posted the code on stackoverflow

  16. Ben Seshi

    hey how can i connect to my local database to get data from and to plot candlestick graph

  17. Ben Seshi

    im having so trouble in making it happen can u help me with that

  18. Ken Rosenberg

    does anyone know how to do it with quandl dataframe, i mean getting a quandl dataframe and then plotting a candlestick graph from it.

  19. Anthony

    It may be worth noting that since it is deprecated, you’ll need to install mpl_finance with Anaconda Python terminal, not regular windows CMD. It wouldn’t work for me with just the windows edition, had to do it in Anaconda.

    1. Minespidur

      I installed it with Windows and when I run the program, nothing happens. Is there any reason why it doesn’t load through Windows?

  20. WildRover1964

    I’m loving this series but could you do a whole vid on your interesting profanities. Goshdarnit anyone working with code needs a rich library of invective and you have a rich new one 😂…… Killing me smalls 😂😂

Leave a Comment