JuliaPlots / GraphRecipes.jl

Graph-related recipes to be used with Plots.jl
Other
168 stars 28 forks source link

graphplot(Graph(3,3)) fails with PGFPlots backend #28

Open sbromberger opened 7 years ago

sbromberger commented 7 years ago

So many intertwined dependencies - not sure where to report this.

julia> z = graphplot(Graph(3,3))
1mERROR: LaTeX error
Stacktrace:
 [1] save(::TikzPictures.PDF, ::TikzPictures.TikzPicture) at /Users/bromberger1/.julia/v0.6/TikzPictures/src/TikzPictures.jl:211
 [2] _show(::IOStream, ::MIME{Symbol("application/pdf")}, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Plots/src/backends/pgfplots.jl:403
 [3] show(::IOStream, ::MIME{Symbol("application/pdf")}, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Plots/src/output.jl:197
 [4] pdf(::Plots.Plot{Plots.PGFPlotsBackend}, ::String) at /Users/bromberger1/.julia/v0.6/Plots/src/output.jl:25
 [5] _show(::Base64EncodePipe, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Plots/src/output.jl:213
 [6] display(::TerminalExtensions.iTerm2.InlineDisplay, ::MIME{Symbol("image/png")}, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/TerminalExtensions/src/TerminalExtensions.jl:93
 [7] display(::TerminalExtensions.iTerm2.InlineDisplay, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/TerminalExtensions/src/TerminalExtensions.jl:103
 [8] display(::Plots.Plot{Plots.PGFPlotsBackend}) at ./multimedia.jl:194
 [9] hookless(::Media.##7#8{Plots.Plot{Plots.PGFPlotsBackend}}) at /Users/bromberger1/.julia/v0.6/Media/src/compat.jl:14
 [10] render(::Media.NoDisplay, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Media/src/compat.jl:27
 [11] display(::Media.DisplayHook, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Media/src/compat.jl:9
 [12] display(::Plots.Plot{Plots.PGFPlotsBackend}) at ./multimedia.jl:194
 [13] eval(::Module, ::Any) at ./boot.jl:235
 [14] print_response(::Base.Terminals.TTYTerminal, ::Any, ::Void, ::Bool, ::Bool, ::Void) at ./REPL.jl:144
 [15] print_response(::Base.REPL.LineEditREPL, ::Any, ::Void, ::Bool, ::Bool) at ./REPL.jl:129
 [16] (::Base.REPL.#do_respond#16{Bool,Base.REPL.##26#36{Base.REPL.LineEditREPL,Base.REPL.REPLHistoryProvider},Base.REPL.LineEditREPL,Base.LineEdit.Prompt})(::Base.LineEdit.MIState, ::Base.AbstractIOBuffer{Array{UInt8,1}}, ::Bool) at ./REPL.jl:646

also

julia> PlotRecipes.savefig(z,"foo.pdf")
! Package pgfplots Error: Sorry, the supplied plot command is unknown or unsupp
orted by pgfplots! Ignoring it..

See the pgfplots package documentation for explanation.
Type  H <return>  for immediate help.
 ...

l.126 mark size = [21.6667, 21.6667, 21.6667],

ERROR: LaTeX error
Stacktrace:
 [1] save(::TikzPictures.PDF, ::TikzPictures.TikzPicture) at /Users/bromberger1/.julia/v0.6/TikzPictures/src/TikzPictures.jl:211
 [2] _show(::IOStream, ::MIME{Symbol("application/pdf")}, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Plots/src/backends/pgfplots.jl:403
 [3] show(::IOStream, ::MIME{Symbol("application/pdf")}, ::Plots.Plot{Plots.PGFPlotsBackend}) at /Users/bromberger1/.julia/v0.6/Plots/src/output.jl:197
 [4] pdf(::Plots.Plot{Plots.PGFPlotsBackend}, ::String) at /Users/bromberger1/.julia/v0.6/Plots/src/output.jl:25
 [5] savefig(::Plots.Plot{Plots.PGFPlotsBackend}, ::String) at /Users/bromberger1/.julia/v0.6/Plots/src/output.jl:116
mykelk commented 7 years ago

I think it comes from this line in PlotRecipes.jl/src/graphs.jl:

markersize --> 10 + 100node_weights / sum(node_weights)

That markersize is an array. Then in pgf_marker in Plots.jl/src/backends/pgfplots.jl results in something like:

mark size = [21.6667,21.6667,21.6667],

but, PGFPlots can only take scalar mark size options. If you change the generated latex code to this:

mark size = 21.6667,

it works! Perhaps, we can change this line in Plots.jl/src/backends/pgfplots.jl from:

mark size = $(0.5 * d[:markersize]),

to

mark size = $(0.5 * maximum(d[:markersize])),
mkborregaard commented 7 years ago

That's a good solution - though I'd suggest mark size = $(0.5 * ignorenan_mean(d[:markersize]))