Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

get_legend_handles_labels() for errorbar plot not working properly

Aperta
#457 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python

Direzione di ricerca

Inizia eseguendo gli esempi Julia nell’issue e ispeziona l’entry point get_legend_handles_labels() e la relativa conversione in PyObject. Confronta gli handle errorbar restituiti con gli oggetti ErrorbarContainer di Python, quindi verifica che l’inversione degli handle mantenga le barre di errore nella legenda.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Related to https://github.com/JuliaPy/PyPlot.jl/issues/401.

I'm simply trying to reverse the order of the legend entries of two errorbar plots.

Pure python (from within Julia):

py"""
import matplotlib.pyplot as plt
import numpy as np
plt.errorbar(np.random.rand(10), np.random.rand(10), np.random.rand(10), label='first', marker='o', linestyle="")
plt.errorbar(np.random.rand(10), np.random.rand(10), np.random.rand(10), label='second', marker='o', linestyle="")
h,l = plt.gca().get_legend_handles_labels()
plt.legend(reversed(h),reversed(l), frameon=True)
"""

image

Using PyPlot:

errorbar(rand(10), rand(10), rand(10), label="first", marker="o", linestyle="")
errorbar(rand(10), rand(10), rand(10), label="second", marker="o", linestyle="")
h,l = gca().get_legend_handles_labels()
legend(reverse(h),reverse(l), frameon=true)

image

Note that the handles are wrong (should be markers with error bars).

PyPlot + ugly fix:

errorbar(rand(10), rand(10), 0.1 .* rand(10), marker="o", linestyle="none", label="first")
errorbar(rand(10), rand(10), 0.1 .* rand(10), marker="o", linestyle="none", label="second")

py"""
import matplotlib.pyplot as plt
h, l = plt.gca().get_legend_handles_labels()
plt.legend(reversed(h), reversed(l), frameon=True)
"""

image

Presumably a PyObject conversion issue? In python, h is a container

[<ErrorbarContainer object of 3 artists>,
 <ErrorbarContainer object of 3 artists>]

In Julia I find

2-element Array{Tuple{PyObject,Tuple{PyObject,PyObject},Tuple{PyObject}},1}:
 (PyObject <matplotlib.lines.Line2D object at 0x000000006FAB9F98>, (PyObject <matplotlib.lines.Line2D object at 0x000000006FAD6780>, PyObject <matplotlib.lines.Line2D object at 0x000000006FAD6EF0>), (PyObject <matplotlib.collections.LineCollection object at 0x000000006FAD6320>,))
 (PyObject <matplotlib.lines.Line2D object at 0x000000006FADF860>, (PyObject <matplotlib.lines.Line2D object at 0x000000006FADFB70>, PyObject <matplotlib.lines.Line2D object at 0x000000006FADFCC0>), (PyObject <matplotlib.collections.LineCollection object at 0x000000006FADF550>,))
Lingua principale
Julia
Stelle
489
Fork
90
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di JuliaPy/PyPlot.jl

Tutte le issue di JuliaPy/PyPlot.jl

Issue simili

Altre issue su Julia

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.