Graphs in Vector Format like PDF/SVG

Is it possible to have the BayesFlow graphs (for example, posteriors or recovery graphs ) in vector formats like SVG or PDF?

Hi,

the BayesFlow plotting functions return a plot object, you can use matplotlib to save that in any format you fancy.

1 Like

I see. Awesome! Thank you very much.

1 Like

This works perfectly on macOS, but I guess either Matplotlib or MS Office apps cannot handle PDF vectors properly on Windows. For example, the shadings are removed in MS Word. Have you ever faced something like this before?

FYI, SVGs work as expected, but they unnecessarily increase the file size. I appreciate your thoughts and feedback.

I haven’t encountered that issue myself. Could you please create a minimal reproducible example so that I can investigate further? Thanks!

Here’s the code I grabbed from the tutorials while saving the figures as PDFs. I’ve also attached the pdf files generated from this code and the screenshot of how it looks on MS Word, Windows, and macOS. I hope it helps.

The link to the files:


Hi Marvin. Did you have a chance to take a look at this? Can we resolve this?

Hi,

thanks for the reminder, and apologies for not getting back to you again in March. I can confirm that it works in Word for MacOS. I pinged a few people with Windows machines and hope that they can reproduce the problem so that we can try to resolve this as a next step.

In the meantime: Is the problem specific to BayesFlow-generated plots? What about other plots that are generated with matplotlib.pyplot?

No worries. Yes, it only happens on Windows machines. I am also a Mac user, and I actually realized this through one of my collaborators working on the shared document on Windows.

I have only seen this on BayesFlow plots when there are shadowed areas like the one you see in the original post. For example, the 95% confidence intervals in ECDF graphs have the same problem.

These actually work as expected when exporting the figures as SVG, but the issue is that SVGs have an unnecessarily large file size compared to PDFs. One workaround I found was to import SVG in MS Word or MS PowerPoint, ungroup the figure (as far as I remember, it only worked when I ungrouped the SVG), and then save the figure as PDF again. This would save the vector format but basically reduce the file size to the same level as the original PDF generated directly through BayesFlow.

I have a hunch that the issue is entirely related to Microsoft/Adobe and how they handle different file formatting rather than matplotlib/BayesFlow/Python. But there might be a way to address this.

Hope it helps,
Ali

Hi Ali,

Thanks for the follow-up info.

Lasse (@elseml) has a standard MS Word installation on a Windows machine. For him, it worked flawlessly. Are there other Windows machines that reproduce the issue?

Also, what about a minimal matplotlib.pyplot plot with semi-transparent elements? Narrowing down the problem from Python and Windows-sides might help pinpoint the issue.

Cheers,
Marvin

I just uploaded two MS Word files on the shared folder:

Lasse (@elseml) could you please check these files (Test 1 and Test 2) on Windows machines? Just to make sure, here is what I see for Test 1 (on a different Windows machine that I would normally use):

Also, @marvinschmitt could you please check on macOS either of the files using ‘Quick Look’? You can do so by doing a right-click on the file and selecting ‘Quick Look’ or selecting the file and hitting the space key. This is what it looks like on my macOS:

But you should be able to see the correct format when you open the file using MS Word:

I’m just trying to make sure that I’m not missing something.

Thank you both!
Ali

Hi Ali,

your docx renders for me the same weird way as for you - but when I insert the pdfs via “Insert > Object > Create from file”, they look perfectly fine. Have you tried that route on your machine?

Best,
Lasse

1 Like

Thank you. It worked, but unfortunately, it treats the PDF as an image and reduces its quality. I couldn’t resolve it by changing the image compression settings. The low quality is even visible in the screenshot below:

So it’s definitely the MS Word problem, especially on Windows, and macOS does some tricks to import the PDF and render it properly. I guess SVG might be a good replacement, although they can be unnecessarily large. Also, I’ve suggested an unusual workaround before using PDFs eventually, and I hope others find it helpful.

Thanks again a lot!
Ali