Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make custom legend with Julia Pyplot

Tags:

graph

plot

julia

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:

enter image description here

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?

like image 657
math_lover Avatar asked Feb 15 '26 22:02

math_lover


1 Answers

I know it is not pyplot but MakieLayout will solve your problem:

enter image description here

Link to the example with code.

I got the answer from Julia Discourse.

like image 139
DisabledWhale Avatar answered Feb 17 '26 20:02

DisabledWhale