DistrictDataLabs / yellowbrick

Visual analysis and diagnostic tools to facilitate machine learning model selection.
http://www.scikit-yb.org/
Apache License 2.0
4.27k stars 555 forks source link

Upgrade manual_legend to match line/marker style of plotted points #566

Open rebeccabilbro opened 6 years ago

rebeccabilbro commented 6 years ago

Describe the solution you'd like Upgrade manual_legend to match line/marker style of plotted points by enabling simple circles and lines with Line2D patches.

Is your feature request related to a problem? Please describe. Right now manual_legend draws the patches as rectangles and cannot take into account the line or scatter plot properties (e.g. line style or marker style). It would be nice to add Line2D patches that would enable the legend to show simple circles or lines to match the marker/line style the user has selected for the plotted points.

image

_Note: This issue is a follow-on to #564, where @bbengfort added a manual_legend to the newly created yellowbrick.draw module, that enabled us to update the visualizers that implement some kind of scatter plot and have an alpha param that affects the opacity/translucency of the plotted points. Now with the manual_legend, the colors in the legend no longer become translucent when alpha is decreased._

Insiyaa commented 5 years ago

Is this issue available? I'd like to take this up!

bbengfort commented 5 years ago

@Insiyaa it is - please feel free!

Insiyaa commented 5 years ago

Hey, I've been struggling with this for a while. Can you point me to a way I can know what kind of plot in passed into the function?

bbengfort commented 5 years ago

Hi @Insiyaa sorry to hear you've been struggling on this, but I'm glad you asked!

The idea is to change the signature of the manual_legend function in yellowbrick.draw:

def manual_legend(g, labels, colors, **legend_kwargs):
    # add legend to g 
    # return legend artist 

At the moment we use labels and colors to add the legend to g (which can be either a Visualizer or a matplotlib Axes object). But by default, we simply add a rectangular patch with the color. What we'd like to do is to also be able to pass style information for Line2D objects.

Ideally, what we'd like is to add a styles=None argument to this function. Styles will be a list of format strings in the form: '[color][marker][line]', e.g. ro is a scatter plot of red circles. See the "Notes" section on format strings [here (https://matplotlib.org/api/_as_gen/matplotlib.pyplot.plot.html) for more details.

If no argument for styles is provided, then we'll simply use the patches as before. If an argument for styles is provided, it must match the number of labels and colors, and it will be used to create the Line2D objects.

Does this make sense? Of course, if you have an alternative suggestion, I'm happy to discuss it further!

lwgray commented 5 years ago

@mlFanatic Thanks again for signing up to be a summer core contributor. Any progress on this issue?