Just an idea with classes and inheritance but I think @johanc links are better:
from matplotlib.lines import Line2D
import matplotlib.pyplot as plt
import matplotlib.patches as pt
class Line2D(Line2D):
def draw(self, rdr):
super().draw(rdr)
xy = self.get_xydata()
start, end = xy[0], xy[-1]
r = pt.Rectangle((start[0] - .05, start[1] - .05), .1, .1,
color=self.get_color(),
fill=None)
plt.gca().add_patch(r)
c = pt.Ellipse(end, .05, .05,
color=self.get_color(),
fill=True)
plt.gca().add_patch(c)
fig = plt.figure()
ax = fig.add_subplot()
rg = [-.5, 1.5]
ax.set_xlim(rg)
ax.set_ylim(rg)
l = Line2D([0, 1], [0, 1], color="green")
ax.add_artist(l)
plt.show()
You can get other parameters (linewidth etc) to apply to your patches objetcs.
