Python Pandas plotting title name passing string
Question: 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']
    


Answer: The way you load data, no name of symbols is saved. OHLC is just a DataFrame,
to my knowledge it has no appropriate name attribute, where `AAPL` symbol can
be stored.

One possible method is to load `Panel`, note square brackets, converting
stock_name to list of symbols:

    
    
    >>> stock_name = 'AAPL'
    >>> OHLC = pd.io.data.DataReader([stock_name],'yahoo',start='01/01/2010')
    >>> OHLC
    <class 'pandas.core.panel.Panel'>
    Dimensions: 6 (items) x 990 (major_axis) x 1 (minor_axis)
    Items axis: Open to Adj Close
    Major_axis axis: 2010-01-04 00:00:00 to 2013-12-06 00:00:00
    Minor_axis axis: AAPL to AAPL
    >>> OHLC.axes[2]
    Index([u'AAPL'], dtype=object)
    

and access underlying DataFrame with

    
    
    >>> OHLC.ix[:,:,'AAPL']
    <class 'pandas.core.frame.DataFrame'>
    DatetimeIndex: 990 entries, 2010-01-04 00:00:00 to 2013-12-06 00:00:00
    Data columns (total 6 columns):
    Open         990  non-null values
    High         990  non-null values
    Low          990  non-null values
    Close        990  non-null values
    Volume       990  non-null values
    Adj Close    990  non-null values
    dtypes: float64(6)
    

Or you can store symbol names yourself,

    
    
    >>> OHLC = (stock_name, pd.io.data.DataReader(stock_name,'yahoo',start='01/01/2010'))
    

and access both df and name with

    
    
    >>> name, df = OHLC
    >>> name
    'AAPL'
    

