Hello everyone! How to add two legends in PyPlot (only). I tried to replicate some Python examples but they use the add_artist function which I don’t find in Julia.
Do you have an MWE where add_artist
errors in Julia? IME it does work exactly the same as in Python, often with literally no code changes.
using PyPlot
"""
When using PyPlot, I avoid using ax.plot, fig.add_subplot, etc.
It seems that here I could not.
MWE = message error warning?
IME = ?
"""
function test()
# Generate data for plotting
x = range(0, 2π, 100)
y0 = sin.(x)
y1 = sin.(x * 0.9) * 0.9
# Find their maxima and minima and store
maxes, mines = zeros(2,2), zeros(2,2)
for (k,y) in enumerate([y0,y1])
i = argmax(y); maxes[k,:] = [x[i], y[i]]
i = argmin(y); mines[k,:] = [x[i], y[i]]
end
# plot y0, y1
fig = figure()
ax = fig.add_subplot(111)
ax.plot(x, [y0 y1], label=["y0","y1"])
# Plot maxima and minima
maxline, = ax.plot(maxes[:,1], maxes[:,2], "r^")
minline, = ax.plot(mines[:,1], mines[:,2], "ko")
leg1 = ax.legend(loc=3)
leg2 = ax.legend([maxline,minline], ["max","min"], loc=1)
ax.add_artist(leg1)
end
Thanks @aplavin.