Question:
How do I add horizontal lines to a plot
based on the sort_values
criteria specified below captured in the top_5
variable.:
Data:
Here is a slice of the data in a CSV:
This is the current plot.
axnum = today_numBars_slice[['High','Low']].plot()
axnum.yaxis.set_major_formatter(FormatStrFormatter('%.2f'))
This is the data I want to add to this plot (the High
and Low
values from each row):
top_5 = today_numBars_slice[['High','Low','# of Trades']].sort_values(by='# of Trades',ascending=False).head()
top_5
High Low # of Trades
Timestamp
2017-01-02 12:55:09.100 164.88 164.84 470
2017-01-02 12:10:12.000 164.90 164.86 465
2017-01-02 12:38:59.000 164.90 164.86 431
2017-01-02 11:54:49.100 164.87 164.83 427
2017-01-02 10:52:26.000 164.60 164.56 332
Desired output:
This is an example of the desired output showing two of the lines from top_5:
You can use faster
DataFrame.nlargest
for top5
rows and theniterrows
with axhline:Also subset is not necessary: