Created
February 13, 2018 15:02
-
-
Save evanmiltenburg/3758d7d0a41abfcbb20f6ba49fba9da8 to your computer and use it in GitHub Desktop.
Circles in legend
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import matplotlib.pyplot as plt | |
import seaborn as sns | |
from matplotlib.lines import Line2D | |
my_palette = sns.color_palette("cubehelix", 3) | |
sns.set_palette(my_palette) | |
def legend_circles(labels, palette, loc=1, markersize=10, marker='o', padding=0): | |
"Make a legend where the color is indicated by a circle." | |
legend_markers = [Line2D(range(1), range(1), | |
linewidth=0, # Invisible line | |
marker=marker, | |
markersize=markersize, | |
markerfacecolor=palette[i]) for i in range(len(labels))] | |
return plt.legend(legend_markers, labels, numpoints=1, loc=loc, handletextpad=padding) | |
plt.plot([1,2,3]) | |
plt.plot([0,1,3]) | |
plt.plot([3,2,1]) | |
legend = legend_circles(['a','b','c'], my_palette,loc=0) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example output:
