This is probably a very simple question, but I'm new to python and can't figure it out. I'm trying to use matplotlib within a user-defined function, but I'm getting an error message. Here's the code I'm using:
def CreateInterval(start,stop):
interval=dates[(dates['Date']>=start)&(dates['Date']<=stop)]
plt.bar(interval['Date'],interval['Trips'])
plt.xlabel('Date')
plt.ylabel('Number Trips')
plt.title('Number of trips during the interval',start,stop)
plt.show()
CreateInterval('2012-03-13','2012-04-13')
As you can see, this code takes a user defined slice of the "dates" dataframe (a pandas object) and attempts to graph it (with a bar indicating the number of trips for each day in the slice).
When I run this code, I get an empty plot space and an error message "key error: 0"
Is it possible to use matplotlib within a user function like this? If so, how?
*Also, I know there is another stackoverflow question with a similar title to mine, but I don't think it answers my question.
Thanks!
start,stop
in your call totitle
?title
.dates
? It's likely to be a problem with the input rather than the plotting, but it's hard to tell with only a snippet of code