1

I want to use matplotlib to plot date chart,but it show invalid literal for float(): 2014-12-10

I have input the x ,y and I want to marker the plot.

x:

Index([u'2000-03-07', u'2000-03-10', u'2000-04-20', u'2002-06-11', u'2003-02-14', u'2004-05-06', u'2004-10-19', u'2005-04-18', u'2005-08-31', u'2005-10-12', u'2006-06-13', u'2006-09-14', u'2008-04-03', u'2010-02-08', u'2011-03-18', u'2012-10-23', u'2013-06-26', u'2014-12-10'], dtype='object')

y:

Date
2000-03-07    9491.051618
2000-03-10    9469.455775
2000-04-20    9351.822824
2002-06-11    5518.155692
2003-02-14    4636.945801
2004-05-06    6153.815709
2004-10-19    5894.815639
2005-04-18    5939.381487
2005-08-31    6097.665806
2005-10-12    6090.384208
2006-06-13    6516.404297
2006-09-14    6664.298549
2008-04-03    8598.774275
2010-02-08    7445.492815
2011-03-18    8423.934431
2012-10-23    7419.858538
2013-06-26    7845.241420
2014-12-10    9141.440151
Name: short_sma, dtype: float64

I use the code is below:

ax1.plot(dfr.ix[dfr['sig']=='EXIT'].index, 
                 dfr.short_sma[dfr['sig']=='EXIT'],
                 'v', markersize=10, color='k' ,label='sell')

Below is pic I want to marker to it.

Thank you very much.

enter image description here

ali_m
  • 71,714
  • 23
  • 223
  • 298
yensheng
  • 1,315
  • 2
  • 14
  • 22

1 Answers1

2

You need to convert your axis to type datetime. Lots of ways to do this, but assuming it is already a pandas Series, the easiest way is pandas.to_datetime:

ax1.plot(pd.to_datetime(dfr.ix[dfr['sig']=='EXIT'].index),
    dfr.short_sma[dfr['sig']=='EXIT'],
    'v', markersize=10, color='k' ,label='sell')
mattexx
  • 6,456
  • 3
  • 36
  • 47