0

I'm trying to create a custom legend for my seaborn plots.

Using the following I can create a custom legend using square patches. What I want is something similar but with point in round, caret, squares and diamond shapes with the same color as the patches. I have no clue howto.

import matplotlib.pyplot as plt
import matplotlib.patches as mpatches

f, ax = plt.subplots(1,1,figsize=(25, 10))

green_patch = mpatches.Patch(color='green', label='Acceptor Gain')
red_patch = mpatches.Patch(color='red', label='Acceptor loss')
blue_patch = mpatches.Patch(color='blue', label='Donor Gain')
orange_patch = mpatches.Patch(color='orange', label='Donor loss')


ax.legend(handles=[green_patch, red_patch, blue_patch, orange_patch])
Fenrir
  • 85
  • 1
  • 5
  • `legend_elements = [Line2D([0], [0], marker='D', color='green', label='...'), ...]`. See [Composing custom legends](https://matplotlib.org/stable/gallery/text_labels_and_annotations/custom_legends.html) – JohanC Apr 20 '21 at 12:10
  • kind of, except that the marker has a line through it. I would need a single point in the legend – Fenrir Apr 20 '21 at 15:02
  • The last example in [Composing custom legends ](https://matplotlib.org/stable/gallery/text_labels_and_annotations/custom_legends.html) has a dot without line. You can add `linestyle=''` to make sure there isn't a line. – JohanC Apr 20 '21 at 15:33

0 Answers0