动态注释matplotlib图?

时间:2018-10-18 00:29:41

标签: python matplotlib

我正在绘制一些图,在第二个图上,每次图形越过红线或绿线时,我都试图突出显示。就其本身而言,我可以在所有注释都正常工作的情况下很好地生成图。

date = np.vectorize(dt.datetime.fromtimestamp)(time_data) # makes a datetimeobject from unix timestamp
date = np.vectorize(mdates.date2num)(date) # from datetime makes matplotib time
myFmt = mdates.DateFormatter('%d-%m-%Y')

#main btc price data close
ax1 = plt.subplot2grid((10,2), (0,0), rowspan=4, colspan=4)
#plt.gcf().gca().xaxis.set_major_formatter(myFmt) #get the current axes and figure
ax1.xaxis.set_major_formatter(myFmt)
ax1.plot(date,close_data)

#rsi
ax2 = plt.subplot2grid((10,2), (5,0), sharex=ax1, rowspan=2, colspan=4)
ax2.xaxis.set_major_formatter(myFmt)
ax2.plot(date, rsi_graph)

# ax2.plot(date, rsi_graph)
ax2.axhline(y=70, xmin=0, xmax=1, color="r")
ax2.axhline(y=30, xmin=0, xmax=1, color="g")
ax2.set_yticks([70,50,30])

rsi_check_1_only = rsi_check_1[:,1] # x coordinate
rsi_check_1_close = rsi_check_1[:,2] # text to annotate

for rsi, date_2, close in zip(rsi_check_1_only, date, rsi_check_1_close):
    ax2.annotate(close, xy = (date_2, rsi), rotation=45)

plt.show()

enter image description here

当我将用于创建注释的循环复制到第二个图中时,它们都被涂抹到了左下角。注释应分布在图的整个长度和时间格式上。 同样奇怪的是,第二个图仅在注释之后才开始生成。

感谢所有想法。干杯

0 个答案:

没有答案