Changing the background color in a graphics tool

I am going to use a python package named graph-tool to render graphs. For some reason, it sets the background to gray every time, keeping the graph looking far from pleasing. Does anyone know how to change it to white?

For example, this example code:

from graph_tool.all import *
g = price_network(5000)
p = sfdp_layout(g)
graph_draw(g, pos=p, output="example.png")

      

runs on an iPython laptop, displays a graph with a white background on the screen, but the saved image has a gray background.

The result is the same as the format used for the output (at least with .png, .pdf and .svg). There was no such problem with networkX, but graphical drawing is slower and much less flexible.

Thanks for any help!

+3


source to share


2 answers


You should just pass the parameter bg_color

to graph_draw (). For example:

graph_draw(g, pos=p, bg_color=[1,1,1,1], output="example.png")

      



will create a white background instead of a transparent one.

+3


source


The "gray background" you see is your PNG viewer for rendering a transparent background. For example, I see a checkerboard pattern on my screen:

enter image description here

but when i load the image or print it wherever there is (default) white background:



enter image description here

Flatten the image in the editor to remove the alpha channel if that worries you.

In theory, you should go gprops={"bgcolor":"white"}

up to graph_draw , but that doesn't work for me.

+2


source







All Articles