JuliaPy / JuliaPy/PyPlot.jl

Unable to show legend in surface plot

Ouverte
#350 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
Langage dominant
Julia
Étoiles
488
Forks
90
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

Hi all,

i am getting the following error when i try to add a legend to an existing plot;
the code is the following:
`using PyPlot;`
`x=collect(linspace(0,1,100));`
`y=collect(linspace(0,2,20));`
`f(x,y)=sin.(x).*cos.(y);`
`g(x,y)=sin.(x).*sin.(y);`
`z1=[f(x_i,y_j) for x_i in x, y_j in y]`
`z2=[g(x_i,y_j) for x_i in x, y_j in y]`
`surf(x,y,z1')`
`surf(x,y,z2')`
`legend(["Function1","Function2"])`

When i try to execute this code in the julia REPL i have no error and the legend shows up;
![image](https://user-images.githubusercontent.com/22870673/37401754-6a052508-2789-11e8-8e61-e554a2eb0ce4.png)

but when i save the code in a script file and try to execute that through include("filename.jl") i am getting the following error and the legend does not show up:

ERROR: LoadError: PyError (ccall(@pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, arg, C_NULL))
AttributeError("'Poly3DCollection' object has no attribute '_edgecolors2d'",)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\pyplot.py", line 3744, in legend
ret = gca().legend(*args, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\axes\_axes.py", line 500, in legend
self.legend_ = mlegend.Legend(self, handles, labels, **kwargs)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\legend.py", line 697, in __init__
self._init_legend_box(handles, labels, markerfirst)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\legend.py", line 957, in _init_legend_box
fontsize, handlebox))
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\legend_handler.py", line 119, in legend_artist
fontsize, handlebox.get_transform())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\legend_handler.py", line 733, in create_artists
self.update_prop(p, orig_handle, legend)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\legend_handler.py", line 76, in update_prop
self._update_prop(legend_handle, orig_handle)
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\matplotlib\legend_handler.py", line 716, in _update_prop
orig_handle.get_edgecolor())
File "C:\Users\Administrator\AppData\Local\Programs\Python\Python36\lib\site-packages\mpl_toolkits\mplot3d\art3d.py", line 706, in get_edgecolors
return self._edgecolors2d

Stacktrace:
[1] pyerr_check at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyCall\src\exception.jl:56 [inlined]
[2] pyerr_check at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyCall\src\exception.jl:61 [inlined]
[3] macro expansion at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyCall\src\exception.jl:81 [inlined]
[4] #_pycall#67(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Array{String,1}, ::Vararg{Array{String,1},N} where N) at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyCall\src\PyCall.jl:653 [5] _pycall(::PyCall.PyObject, ::Array{String,1}, ::Vararg{Array{String,1},N} where N) at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyCall\src\PyCall.jl:641 [6] #pycall#71(::Array{Any,1}, ::Function, ::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Array{String,1}, ::Vararg{Array{String,1},N} where N) at C:\JuliaPro-0.6.
2.2\pkgs-0.6.2.2\v0.6\PyCall\src\PyCall.jl:675 [7] pycall(::PyCall.PyObject, ::Type{PyCall.PyAny}, ::Array{String,1}, ::Vararg{Array{String,1},N} where N) at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyCall\src
\PyCall.jl:675 [8] #legend#72(::Array{Any,1}, ::Function, ::Array{String,1}, ::Vararg{Array{St
ring,1},N} where N) at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyPlot\src\PyPlot.jl:172
[9] legend(::Array{String,1}, ::Vararg{Array{String,1},N} where N) at C:\JuliaPro-0.6.2.2\pkgs-0.6.2.2\v0.6\PyPlot\src\PyPlot.jl:169 [10] include_from_node1(::String) at .\loading.jl:576
[11] include(::String) at .\sysimg.jl:14
while loading C:\Users\Administrator\Desktop\JuliaProjects\BrokenPyPlot.jl, in expression starting on line 13`

Do you have any idea?
Am I making some mistakes?

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Run the provided Julia script via include("filename.jl") and compare it with the REPL behavior. Start from PyPlot.legend in the stack trace and the matplotlib Poly3DCollection legend handling. Done means the surface plot legend renders without the _edgecolors2d AttributeError when loaded from a script.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
julia, python
Domaine
data-visualization
Type d'issue
Bug
Difficulté
3/5
Temps estimé
1-2 jours
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
45/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.