Question

Ta-Lib for Python - version:0.4.7.

Issue: Talib.MACD - Histo plotting line instead of histogram

Python 3.3.2 Matplotlib 1.2.1, Numpy 1.7.1! OS: Windows 7

I am trying to add MACD, using Ta-lib. The histogram is plotting as Line instead of histogram. Need your guidance to sort it out.

(I tried to attach the image, but unable to do so due to lack of reputations.)

I am very much a fresher to programming and to Python as well as to other packages I am using. Your guidance will help me improve further.

My code:

Calculation:

macd = macd, macdsignal, macdhist = talib.MACD(r.close, 12, 26, 9)

Plotting:

ax1 = fig1.add_subplot(211, frameon=True)
    macd = ax1.plot(macd, color='green')
    macd = ax1.plot(macdsignal, color='red')
    macd = ax1.plot(macdhist, color='blue')

Thanks in advance

Regards

Suresh

Was it helpful?

Solution

I'm not sure what Talib or MACD are, but I think you just need to replace your ax1.plot() with ax1.hist(macd, bins=50). There are a bunch of options but provided macd is just the set of data you want to bin and put into a histogram this should work.

The matplotlib documentation has enough to get you going an example:

http://matplotlib.org/api/pyplot_api.html#module-matplotlib.pyplot

you will need to Ctrl-f to find matplotlib.pyplot.hist.

If instead your macd is already binned then you may need to use ax1.bar() instead:

http://matplotlib.org/examples/api/barchart_demo.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top