GraphRecipes.jl icon indicating copy to clipboard operation
GraphRecipes.jl copied to clipboard

broken graph example on pyplot

Open CarloLucibello opened this issue 8 years ago • 6 comments

running one of the graph examples on julia 0.5.1 I get this

julia> using PlotRecipes

julia> n = 15
15

julia> A = Float64[(rand()<0.5 ? 0 : rand()) for i=1:n,j=1:n];

julia> for i=1:n
           A[i,1:i-1] = A[1:i-1,i]
       end

julia> node_weights = 1:n;

julia> graphplot(A,
           node_weights = 1:n,
           marker = (:heat, :rect),
           line = (3, 0.5, :blues),
           marker_z = 1:n,
           names = 1:n
       )

 If the code has a Segmentation fault error switch to qt v4.8.5 by pasting the following code into julia: 
 
if !Plots.is_installed("PyPlot")
    Pkg.add("PyPlot")
end
withenv("PYTHON" => "") do
    Pkg.build("PyPlot")
end
import Conda
Conda.add("qt=4.8.5")

# now restart julia!
Error showing value of type Plots.Plot{Plots.PyPlotBackend}:
ERROR: PyError (:PyObject_Call) <class 'ValueError'>
ValueError('Invalid RGBA argument: 1.0',)
  File "/usr/lib/python3.6/site-packages/matplotlib/__init__.py", line 1892, in inner
    return func(ax, *args, **kwargs)
  File "/usr/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 4028, in scatter
    alpha=alpha
  File "/usr/lib/python3.6/site-packages/matplotlib/collections.py", line 890, in __init__
    Collection.__init__(self, **kwargs)
  File "/usr/lib/python3.6/site-packages/matplotlib/collections.py", line 139, in __init__
    self.set_facecolor(facecolors)
  File "/usr/lib/python3.6/site-packages/matplotlib/collections.py", line 674, in set_facecolor
    self._set_facecolor(c)
  File "/usr/lib/python3.6/site-packages/matplotlib/collections.py", line 659, in _set_facecolor
    self._facecolors = mcolors.to_rgba_array(c, self._alpha)
  File "/usr/lib/python3.6/site-packages/matplotlib/colors.py", line 237, in to_rgba_array
    result[i] = to_rgba(cc, alpha)
  File "/usr/lib/python3.6/site-packages/matplotlib/colors.py", line 143, in to_rgba
    rgba = _to_rgba_no_colorcycle(c, alpha)
  File "/usr/lib/python3.6/site-packages/matplotlib/colors.py", line 194, in _to_rgba_no_colorcycle
    raise ValueError("Invalid RGBA argument: {!r}".format(orig_c))

If I don't pass the names=1:n argument instead I get no errors and the plot is correctly visualized

Bye, Carlo

CarloLucibello avatar Mar 29 '17 07:03 CarloLucibello

There is a current bug in Plots that makes the pyplot backend fail with this error message when marker_z is specified. The workaround for now is to use a different backend.

mkborregaard avatar Mar 29 '17 08:03 mkborregaard

@mkborregaard this works:

julia> graphplot(A,
           node_weights = 1:n,
           line = (3, 0.5, :blues),
           marker_z = 1:n,
           marker=(:heat,:rect)
       )

CarloLucibello avatar Mar 29 '17 08:03 CarloLucibello

Interesting, - what is your Pkg.status for PyPlot, Plots, PlotRecipes, and the output of PyPlot.version?

mkborregaard avatar Mar 29 '17 08:03 mkborregaard

I get this behviour on this setup

# julia 0.5.1

julia> Pkg.status("PyPlot")
 - PyPlot                        2.3.1

julia> Pkg.status("Plots")
 - Plots                         0.10.3+            master

julia> Pkg.status("PlotRecipes")
 - PlotRecipes                   0.2.0+             master

julia> import PyPlot

julia> PyPlot.version
v"2.0.0"

and also after a Pkg.free("Plots"); Pkg.free("PlotRecipes")

CarloLucibello avatar Mar 29 '17 19:03 CarloLucibello

I get it too now - the issue is nodeshape in this line: https://github.com/JuliaPlots/PlotRecipes.jl/blob/master/src/graphs.jl#L370. The issue is that defining names and markershape at the same time causes nodeshape to be reinterpreted as a Plots.Shape, and I think that Shape together with having marker_z defined causes some issues that may have to do with line_z internally in Plots, which is buggy in pyplot()... I can't look at it more now (application writing!) but may give it a try later. I haven't had any luck with this particular bug, though. You can avoid the issue also by not defining markershape (set to :rect in the above call).

mkborregaard avatar Mar 29 '17 20:03 mkborregaard

Thanks for the effort, that almost did it:

# NOT WORKING
julia> graphplot(A,
           node_weights = 1:n,
           line = (3, 0.5, :blues),
           marker_z = 1:n,
           names = 1:n
       )

# WORKING
julia> graphplot(A,
           node_weights = 1:n,
           line = (3, 0.5, :blues),
           names = 1:n
       )

CarloLucibello avatar Mar 29 '17 21:03 CarloLucibello