在python matplotlib中鼠标悬停时X轴值不可见
我试图在X轴上绘制一些Y轴的值与时间的关系。一切正常,但当我将鼠标悬停在图形线上时,我只得到带有格式化标签的Y轴的值。我尝试了许多方法,但无法理解并实现在同一个悬停框中获取X轴的值在python matplotlib中鼠标悬停时X轴值不可见,python,matplotlib,Python,Matplotlib,我试图在X轴上绘制一些Y轴的值与时间的关系。一切正常,但当我将鼠标悬停在图形线上时,我只得到带有格式化标签的Y轴的值。我尝试了许多方法,但无法理解并实现在同一个悬停框中获取X轴的值 import time from time import strftime import matplotlib.pyplot as plt import matplotlib.animation as animation import random from mpldatacursor import datacurs
import time
from time import strftime
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import random
from mpldatacursor import datacursor
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
xs = []
ys = []
def animate(i,xs,ys):
rand_list = []
###### Generate Two random input values ######
for i in range(0,2):
data_1 = random.uniform(0,1.2)
rand_list.append(data_1)
####### Append the two random numbers in Y axis list ############
ys.append(rand_list)
####### Append Current Time to the X-axis list ########
xs.append(time.strftime('%X'))
ax.clear()
#### Plotting the X and Y lists on the axes ###########
plt.gcf().autofmt_xdate()
plt.xticks(rotation=45)
#datacursor(ax.plot(xs,ys,linestyle='-'),hover=True,formatter='Time:{}'.format(statement))
#################### This is the line where i am trying to format the label and get the value in hover box
datacursor(ax.plot(xs,ys, linestyle='-'),hover=True, formatter='TGI Value: {y:.2f}'.format)
plt.xlabel("Time")
plt.ylabel("TGI Value")
ani = animation.FuncAnimation(fig, animate, fargs=(xs,ys), interval=10000)
### Display the graph #####
#plt.gcf().autofmt_xdate()
plt.show()
我已经在悬停框中实现了Y轴值。我现在需要在悬停框中实现X轴的时间值
这是当前图形,鼠标悬停时仅显示TGI值。需要X轴上显示的时间也在同一个悬停框中吗