Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node colors not saving to .pdf #156

Open
SimonEnsemble opened this issue Sep 14, 2021 · 6 comments
Open

node colors not saving to .pdf #156

SimonEnsemble opened this issue Sep 14, 2021 · 6 comments

Comments

@SimonEnsemble
Copy link

oddly the node colors are not saving when I save to .pdf.

after

gp = gplot(SimpleGraph(xtal.bonds), 
	       nodefillc=node_colors, 
	       nodestrokec=colorant"black", 
	       nodestrokelw=0.5)

what Pluto.jl displays:
image
after

draw(PDF("IRMOF-1_graph.pdf", 12cm, 12cm), gp)

what the .pdf looks like:
image

@SimonEnsemble
Copy link
Author

very oddly, I cannot re-create this behavior with the minimal example below!

	my_graph = SimpleGraph(350)
	add_edge!(my_graph, 1, 3)
	colorz = [colorant"red" for i = 1:nv(my_graph)]
	my_gp = gplot(my_graph, nodefillc=colorz, nodestrokec=colorant"black", nodestrokelw=1)
	draw(PDF("toy_graph.pdf", 8cm, 8cm), my_gp)

@SimonEnsemble
Copy link
Author

mk this is bizarre. the PDF function properly saves color when I put the gplot(...) directly into the function draw. so

draw(PDF("toy_graph.pdf", 8cm, 8cm), gplot(...))

totally works! it was defining the output of gplot to be gp then passing it to draw that caused this odd behavior of leaving out colors. actually if I view gp again in a separate Pluto.jl cell, the colors disappear. odd right?

image

@tomtuamnuq
Copy link

When I ran the following code in Jupyter Notebook the nodes are black:

 my_graph = SimpleGraph(100)
 add_edge!(my_graph, 1, 3)
 colorz = [colorant"red" for i = 1:nv(my_graph)]
 my_gp = gplot(my_graph, nodefillc=colorz)

The same code, but setting the number of Nodes as 99 shows red. Really strange. It also works if I set nodefillc=colorant"red" (both with 99 and 100).
It also works if I change only the first color of the array to something else.
image

When saving to pdf or png the output is always the same as in IJulia Cell.
Maybe the process of saving to pdf is not the problem here.

System Linux Mint with Julia 1.6.3.

@hdavid16
Copy link
Contributor

hdavid16 commented Jul 27, 2022

When I ran the following code in Jupyter Notebook the nodes are black:

 my_graph = SimpleGraph(100)
 add_edge!(my_graph, 1, 3)
 colorz = [colorant"red" for i = 1:nv(my_graph)]
 my_gp = gplot(my_graph, nodefillc=colorz)

I get red nodes in VS Code with the above code. Windows OS. Julia 1.7.

However, when run my_gp on the REPL, the plot colors switch to black....

Decreasing the number of nodes to 99 or just using colorz = colorant"red" fixes the problem, which makes me think this has something to do with the size of the nodefillc....

@hdavid16
Copy link
Contributor

@SimonEnsemble @tomtuamnuq
This is a bug in Compose.jl
A workaround is to ensure that if you use vector inputs, the corresponding inputs for that same Compose object should also be vectors.

From the GraphPlot sourcecode:

    compose(context(units=UnitBox(-1.2, -1.2, +2.4, +2.4)),
            compose(context(), texts, fill(nodelabelc), fontsize(nodelabelsize)),
            compose(context(), nodes, fill(nodefillc), stroke(nodestrokec), linewidth(nodestrokelw)),
            compose(context(), edgetexts, fill(edgelabelc), fontsize(edgelabelsize)),
            compose(context(), arrows, stroke(edgestrokec), linewidth(edgelinewidth)),
            compose(context(), lines, stroke(edgestrokec), linewidth(edgelinewidth)))

If nodefillc is a vector, then nodestrokec and nodestrokelw should also be vectors (of size nv(g)), since these are all used for the nodes object. Doing so will preserve color when saving.

However, this is only an issue for large graphs and will hopefully get fixed in a future release of Compose.jl

@hdavid16
Copy link
Contributor

hdavid16 commented Apr 3, 2023

Or, just use GraphMakie.jl:

 my_graph = SimpleGraph(100)
 add_edge!(my_graph, 1, 3)
 colorz = [colorant"red" for i = 1:nv(my_graph)]
 my_gp = graphplot(my_graph, node_color=colorz)

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants