import numpy as np import matplotlib.pyplot as plt import matplotlib.lines as lines import matplotlib.transforms as mtransforms import matplotlib.text as mtext
classMyLine(lines.Line2D): def__init__(self, *args, **kwargs): # we'll update the position when the line data is set self.text = mtext.Text(0, 0, '') lines.Line2D.__init__(self, *args, **kwargs)
# we can't access the label attr until *after* the line is # initiated self.text.set_text(self.get_label())