I'm setting about to use a python package named graph-tool to visualize graphs. For some reason it sets grey background color each time saving a graph, which looks far from pleasant. Anyone knows how to change it to white?
For example, this sample code:
from graph_tool.all import *
g = price_network(5000)
p = sfdp_layout(g)
graph_draw(g, pos=p, output="example.png")
being run on iPython notebook, displays graph with white background on the screen, but saved picture has grey background.
The outcome is the same whatever format is used for output (at least with .png, .pdf and .svg). With networkX there was no such a problem, but graph drawing there is slower and much less flexible.
Thanks for any help!
You should just pass the bg_color
option to graph_draw(). For example:
graph_draw(g, pos=p, bg_color=[1,1,1,1], output="example.png")
will produce a white background, instead of transparent.
The "grey background color" that you see is your PNG viewers way of rendering the transparent background. For example, I see a checkerboard pattern on my screen:
but when I upload the image or print it out anywhere it has a (default) white background:
Flatten the image in an editor to remove the alpha channel if it bothers you.
In theory you should be able to pass gprops={"bgcolor":"white"}
to graph_draw but this doesn't work for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With