import matplotlib.pyplot as plt
import numpy as np
from matplotlib.ticker import ScalarFormatter
import mplcursors as mpl
class Compound():
def accumulation(i,t):
return (1+i)**t
def discount(i,t):
return (1-i)**(-t)
years= np.linspace(1,1000,12000)
%matplotlib widget
fig, ax = plt.subplots()
ax.yaxis.set_major_formatter(ScalarFormatter(useMathText=True))
plt.plot(years,0.93*Compound.accumulation(0.0225,years))
plt.title('Interest')
mpl.cursor(hover=True).annotation_kwargs
I'm using a Jupiter notebook and I want to change the scientific format in the annotation that mplcursors creates when the cursor hovers above the lines
The
mplcursorspackage uses the matplotlibAxes.format_coordto set the style of the formatters in the annotation box. So, you can define your ownformat_coordfunction and use that instead (see, e.g., here).For example,
Unfortunately, this doesn't seem to work with LaTeX/MathText style strings enclosed in $ signs, e.g., using:
keeps the dollars and does not render it as an equation. Doing that may required a more in-depth hack.