trock2000
trock2000

Reputation: 312

ValueError: Invalid chart type given scatter

I am new to Python and I am trying to plot a simple scatter plot for 2 stocks (Adj Close). For some reason I am unable to generate a scatter plot (when I remove the kind='scatter' argument, the chart runs as expected, but is a line chart). Here is my code:

from pandas.io.data import DataReader
from datetime import datetime
import matplotlib.pyplot as plt

#inputs
symbols   = ['SPY', 'QQQ']
startDate = datetime(2013,1,1)
endDate   = datetime(2016,12,31)

#get data from yahoo
instrument = DataReader(symbols, 'yahoo', startDate, endDate)
#isolate column
close = instrument['Adj Close']

def compute_daily_returns(df):
    daily_returns = (df / df.shift(1)) - 1
    return daily_returns

dlyRtns = compute_daily_returns(close)
xPlt = dlyRtns['SPY']
yPlt = dlyRtns['QQQ']

dlyRtns.plot(kind='scatter', x=xPlt, y=yPlt)
plt.show()

and here is the resulting error message (any ideas on what I am missing?):

Traceback (most recent call last): File "C:/Users/sferrom/PycharmProjects/untitled2/scatterPlot.py", line 27, in dlyRtns.plot(kind='scatter', x=xPlt, y=yPlt) File "C:\Python27\lib\site-packages\pandas\tools\plotting.py", line 1537, in plot_frame raise ValueError('Invalid chart type given %s' % kind) ValueError: Invalid chart type given scatter

Process finished with exit code 1

Upvotes: 0

Views: 435

Answers (1)

ragesz
ragesz

Reputation: 9527

"Create" scatter plot from line chart if line works:

dlyRtns.plot(x=xPlt, y=yPlt, marker='o', linewidth=0)

Upvotes: 1

Related Questions