JuliaPlots/GraphRecipes.jl

`method=:spectral' fails?

xiaoweiz opened this issue · 0 comments

It appears that setting `method=:spectral' fails if the graph has an isolated node.
For example, let's create a graph with one isolated node.

using LightGraphs, GraphRecipes, Plots
g = barabasi_albert(20, 5, 4)
graphplot(g, curves=false, method=:stress)

Screenshot 2020-05-28 at 5 13 32 AM

Set `method=:spectral'.

graphplot(g, curves=false, method=:spectral)
ERROR: InexactError: Float64(-0.9544527372853698 + 0.04554726271463011im)
Stacktrace:
 [1] Real at ./complex.jl:37 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] convert at ./essentials.jl:310 [inlined]
 [4] convert at /Users/xiaoweizhang/.julia/packages/GeometryTypes/gpBFp/src/FixedSizeArrays.jl:139 [inlined]
 [5] setindex!(::Array{GeometryTypes.Point{3,Float64},1}, ::Tuple{Complex{Float64},Complex{Float64},Complex{Float64}}, ::Int64) at ./array.jl:826
 [6] layout!(::Array{Float64,2}, ::Array{Float64,1}) at /Users/xiaoweizhang/.julia/packages/NetworkLayout/hUKo2/src/spectral.jl:60
 [7] #layout#1 at /Users/xiaoweizhang/.julia/packages/NetworkLayout/hUKo2/src/spectral.jl:49 [inlined]
 [8] #spectral_graph#15 at /Users/xiaoweizhang/.julia/packages/GraphRecipes/kYXc4/src/graph_layouts.jl:9 [inlined]
 [9] macro expansion at /Users/xiaoweizhang/.julia/packages/GraphRecipes/kYXc4/src/graphs.jl:389 [inlined]
 [10] apply_recipe(::Dict{Symbol,Any}, ::GraphRecipes.GraphPlot) at /Users/xiaoweizhang/.julia/packages/RecipesBase/jcXIg/src/RecipesBase.jl:281
 [11] _process_userrecipes!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{GraphRecipes.GraphPlot}) at /Users/xiaoweizhang/.julia/packages/RecipesPipeline/5b2IP/src/user_recipe.jl:35
 [12] recipe_pipeline!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{GraphRecipes.GraphPlot}) at /Users/xiaoweizhang/.julia/packages/RecipesPipeline/5b2IP/src/RecipesPipeline.jl:68
 [13] _plot!(::Plots.Plot{Plots.GRBackend}, ::Dict{Symbol,Any}, ::Tuple{GraphRecipes.GraphPlot}) at /Users/xiaoweizhang/.julia/packages/Plots/vAz7I/src/plot.jl:167
 [14] plot(::GraphRecipes.GraphPlot; kw::Base.Iterators.Pairs{Symbol,Any,Tuple{Symbol,Symbol},NamedTuple{(:curves, :method),Tuple{Bool,Symbol}}}) at /Users/xiaoweizhang/.julia/packages/Plots/vAz7I/src/plot.jl:57
 [15] #graphplot#82 at /Users/xiaoweizhang/.julia/packages/RecipesBase/jcXIg/src/RecipesBase.jl:356 [inlined]
 [16] top-level scope at REPL[29]:1

It'd work if the graph is connected.

g = barabasi_albert(20, 5, 5)
graphplot(g, curves=false, method=:spectral)

Screenshot 2020-05-28 at 5 16 15 AM