Here is a simplified plot of the situation:
Instead of have each data point marker have a separate label, I want to be able to have one label for a set of different markers. I would like to be able to have a legend like:
<triangle> <square> <hexagon> <diamond> <circle> Shotcrete strength data points
<green line> 10 minute strength
<blue line> 60 minute strength
<yellow line> 1 day strength
<orange line> 7 day strength
<red line> 28 day strength
I want to do this because in the final plot I will have three sets of data points and showing 18 (3 sets * 6 points/set) marker/label combinations will be messy.
I am using Matplotlib with Python 2.7.
Note: This answer is kept up as a guide to the correct answer - but it does not solve the stated problem. Please see the edit below for the problem of Patch collections not being support in matplotlib.
One way to go about this, if you want complete customization is to use a so-called Proxy Artist:
from pylab import *
p1 = Rectangle((0, 0), 1, 1, fc="r")
p2 = Circle((0, 0), fc="b")
p3 = plot([10,20],'g--')
legend([p1,p2,p3], ["Red Rectangle","Blue Circle","Green-dash"])
show()
Here you can specify exactly what you'd like the legend to look like, and even use non-standard plot shapes (patches).
Edit: There is some difficulty with this method, matplotlib only supports these Artists in a legend without tweaking. For matplotlib v1.0 and earlier, the supported artists are as follows.
Line2D
Patch
LineCollection
RegularPolyCollection
CircleCollection
Your request of multiple scatter points would be done with a Patch Collection, which is not supported above. In theory with v1.1, this is possible but I do not see how.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With