Cannot set view background in python

Hi all
I am trying to set the background colour from the python interface (from conda).
I’m doing something like:

for view in [renderView1, renderView2, renderView3, renderView4]:
    view.Background = [0.0, 0.0, 0.0]

ExportView("./blabla.pdf", view=renderView1)

ExportView("./blabla2.pdf", view=renderView2)

ExportView("./blabla3.pdf", view=renderView3)

ExportView("./blabla4.pdf", view=renderView4)

However, the exported pdfs still have the default grey background.

Any idea?

Does this work if you save as PNG instead? Saving as PDF would rasterize the image anyway if you save a RenderView.

Yes I have the same issue when exporting to png

I am able to export with a white background to pdf with the paraview gui

I tried

for view in [renderView1, renderView2, renderView3, renderView4]:
    view.Background = [0.0, 0.0, 0.0]
    SetActiveView(view)
    SetViewProperties(Background=[0.0, 0.0, 0.0])
    Render()
    SaveScreenshot("test.png", view)

And it didn’t work, the background is still grey

I made this MWE from one of the demos.

from paraview.simple import *

ss = Sphere(Radius=2, ThetaResolution=32)
shr = Shrink(Input=ss)

cs = Cone()

app = AppendDatasets()
app.Input = [shr, cs]

Show(app)

SetViewProperties(Background=[0.0, 0.0, 0.0])

Render()

SaveScreenshot("out.png")
ExportView("./out.pdf")

This is out.png. As you can see the background isn’t white
out

SetViewProperties(
   Background=[0.0, 0.0, 0.0],
   UseColorPaletteForBackground = 0,
)
1 Like

@jourdain this seems to have worked!

Turns out I wanted it white but was asking for 0, 0, 0 which is black

Now the issue that I have is that the text is now invisible. Usually with a white background the text turns black. Is there another setting?

image

What about instead of SetViewProperties you use

LoadPalette(paletteName=‘WhiteBackground’)

I got that using

Tools / Start Trace

change the palette to White Background and then

Tools / Stop Trace

That should set all related colors properly.

1 Like

It worked thank you very much!