简体   繁体   中英

Highlighting last data point in pandas plot

I have number of graphs similar to this:

import pandas as pd
dates = pd.date_range('2012-01-01','2013-02-22')
y = np.random.randn(len(dates))/365
Y = pd.Series(y, index=dates)
Y.plot()

在此输入图像描述

The graph is great for showing the shape of the data, but I would like the latest value to stand out as well. I would like to highlight the last data point with a marker 'x' and with a different color. Any idea how I can do this?

在此输入图像描述

Have added Dan Allan's suggestion. Works but I need something a bit more visible. As seen below the x is hardly visible. Any ideas?

Have added return of final answer to complete this. Changed the x to a D for a diamond for better visibility and increased the size of the marker.

Y.tail(1).plot(style='rD',markersize=10)

在此输入图像描述

将此行添加到您的示例中,将最后一个数据点绘制为红色X.

Y.tail(1).plot(style='rx')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM