Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

How do I make the title name display 'AAPL Stock Price' without converting all my pandas data to matplotlib and numpy.

import time
from pylab import *
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from pandas.io.data import *


def Datapull(Stock):
    try:
        OHLC=DataReader(Stock,'yahoo',start='01/01/2010')
        OHLC['diff'] = OHLC.Open - OHLC.Close
        return OHLC
        print 'Retrieved', Stock
        time.sleep(5)
    except Exception, e:
        print 'Main Loop', str(e)

def graph(stock):
    try:
        fig=plt.figure()
        mainplt=plt.subplot2grid((5,4), (0,0), rowspan=4, colspan=4)
        stock['Close'].plot(color='g').set_ylabel('Price')
        plt.title('Stock Price')
        plt.setp(mainplt.get_xticklabels(),  visible=False)

        ax2=plt.subplot2grid((5,4), (4,0), rowspan=1, sharex=mainplt, colspan=4)
        ax2.grid(False)
        stock['Volume'].plot(color='c').set_ylabel('Volume')
        ax2.axes.yaxis.set_ticklabels([])
        plt.setp(ax2.get_xticklabels(),  rotation=45)

        plt.subplots_adjust(top=0.95, bottom=.14, right=.94, left=.09, wspace=.20, hspace=0 )
        plt.show()



    except Exception, e:
        print 'Main Loop', str(e)


Stock='AAPL'
AAPL=Datapull(Stock)
graph(AAPL)

It should be

plt.title(stock+'Stock Price')

using numpy but I get an error message also suptitle does not work either

Main Loop Could not operate ['Stock Price'] with block values [unsupported operand type(s) for +: 'numpy.ndarray' and 'str']
share
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.