I'm making a program to quickly analyze testing curves of battery chargers and such. I would like to combine the hoverbox, which snaps to each curve with a vertical line for easy comparison. If I activate both codes, they collide and I get a line while moving the mouse, when I stop it disappear and the hoverbox doesn't snap to the curves.
The hoverbox is made from the mplcursors library, while the line is made fro the cursor widget in matplotlib.
cursor = Cursor(
ax2, useblit=True, horizOn=False, vertOn=True, color="red", linewidth=0.5
)
mplcursors.cursor(hover=True)
Complete code here:
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Cursor
import mplcursors
data = np.loadtxt("test.txt")
x = data[:, 0]
y = data[:, 1]
y2 = data[:, 2]
y3 = data[:, 3]
fig = plt.figure(figsize=(13, 5))
ax = fig.add_subplot(111)
ax.plot(x, y, "--", label="Voltage")
ax.plot(x, y2, "-.", label="Current")
ax2 = ax.twinx()
ax2.plot(x, y3, "g:", label="Temperature")
ax2.set_ylabel("Celsius", color=("LightBlue"))
ax2.set_ylim(18, 100)
fig.legend(
edgecolor=("DarkBlue"),
facecolor=("LightBlue"),
loc="upper right",
bbox_to_anchor=(1, 1),
bbox_transform=ax.transAxes,
)
ax.set_title("Test Surveillance", color=("Purple"))
ax.set_xlabel("Milliseconds", color=("LightGreen"))
ax.set_ylabel("Volts and Amps", color=("DarkGrey"))
plt.xlim(0)
# cursor = Cursor(
# ax2, useblit=True, horizOn=False, vertOn=True, color="red", linewidth=0.5
# )
mplcursors.cursor(hover=True)
plt.show()
As an added bonus: The X-value is measured in seconds in the example (I know it says milliseconds). I would like to show 1:45:24 or whatever instaid of x=5.77e+04 like in the picture. Is this possible?