Skip to content
Advertisement

adding legend to lineplot according to maplotlib’s axvspan

OK, I have this line plot of data trend over this period.

JavaScript

Figure: enter image description here

But I want to add legend corresponding to each period (coloured) covereds, such that:

  • 2021-03 to 2021-06 the green area bears the legend spring,
  • 2021-06 to 2021-09 blue area is legend summer, and
  • 2021-09 to 2021-12 (magenta) legend winter.

Advertisement

Answer

You can specify a label in the axvspans:

JavaScript

enter image description here

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement