0

Trying to visualize a grid using matplotlib and adding vertical lines in a cycle.

for element in new_gr_4:
    axs.axvline(
        x=element,
        color = 'black',
        linestyle = 'dashed',
        linewidth = 1.0,
        alpha=0.5,
        label='new_grid 4 (weighted)'
        )

If I am trying to show a legend for a plot - I have a lot of elements in a legend with the same visualization parameters (because I have added them in a cycle multiple times).

Is it possible to add a label on a legend for a group, only once?

Or how to add add a separate label on a legend for provided visualization parameters?

twistfire
  • 425
  • 1
  • 5
  • 15
  • 1
    You could try to only set the label for the first element. E.g. something like `label='new_grid 4 (weighted)' if element == new_gr_4[0] else None`. – JohanC Dec 14 '22 at 22:35

0 Answers0