Question about legend rendering

Hi,

Working on mpld3, I’ve hit something I don’t quite know how to handle. I’m trying to render legend components in d3, and the strange thing is that markers within the legend have empty paths. Consider the script below:

···

#------------------------------------------------------

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

line, = ax.plot(range(5), range(5), ‘o’, label=‘dots’)

ax.legend()

print(“here is the marker as it appears in the plot:”)

print(line._marker.get_path())

leg = ax.get_legend()

children = leg.get_children()

print(“here is the marker as it appears in the legend”)

print(children[1]._marker.get_path())

#------------------------------------------------------

On the plot itself, the marker is a circle. On the legend, the marker is an empty path. I’ve tried poking around in the backend code to figure out how the renderers know what path to use when drawing the legend, but the answer is not obvious to me.

Does anyone have insight into what special magic happens here when the legend is rendered? Thanks,

Jake

Jake VanderPlas
Director of Research – Physical Sciences

eScience Institute, University of Washington

http://www.vanderplas.com