I would like to make a custom legend in Julia's pyplot, in which the legend labels are not necessarily related to individual series plotted on the graph. For example:

In Python (pyplot comes from matplotlib) this could be done with:
from matplotlib.lines import Line2D
custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),
Line2D([0], [0], color=cmap(.5), lw=4),
Line2D([0], [0], color=cmap(1.), lw=4)]
fig, ax = plt.subplots()
lines = ax.plot(data)
ax.legend(custom_lines, ['Cold', 'Medium', 'Hot'])
The issue is I cannot seem to access the Line2D object in pyplot (using pyplot as plt, plt.lines.Line2D does not work).
Any workaround?
I know it is not pyplot but MakieLayout will solve your problem:

Link to the example with code.
I got the answer from Julia Discourse.
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