# Graphs in Vector Format like PDF/SVG

**URL:** <https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69>\
**Category:** General\
**Created:** [February 28, 2024, 12:03pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69 "2024-02-28T12:03:47Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [February 28, 2024, 12:03pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/1 "2024-02-28T12:03:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marvinschmitt](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/marvinschmitt/32/98_2.png) [@marvinschmitt](https://discuss.bayesflow.org/u/marvinschmitt)\
**Post date:** [February 28, 2024, 12:17pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/2 "2024-02-28T12:17:23Z")

</div>

Hi,

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

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [February 28, 2024, 12:42pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/3 "2024-02-28T12:42:33Z")

</div>

I see. Awesome! Thank you very much.

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [March 12, 2024, 3:03am UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/4 "2024-03-12T03:03:23Z")

</div>

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.

 ![Screenshot 2024-03-11 at 9.01.36 PM](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/7d079dab89129c2e2c9b2570cacf7f36bbe30f78.png)

---

<div class="post-metadata">

**Author:** ![marvinschmitt](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/marvinschmitt/32/98_2.png) [@marvinschmitt](https://discuss.bayesflow.org/u/marvinschmitt)\
**Post date:** [March 12, 2024, 7:02am UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/5 "2024-03-12T07:02:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [March 12, 2024, 2:33pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/6 "2024-03-12T14:33:45Z")

</div>

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:

> **[Test](https://www.dropbox.com/scl/fo/v4xbs1jgqo9cqg40apu26/h?rlkey=yeemqt5h5yzhqle2ebwja6ccj&dl=0)**
>
> Shared with Dropbox

 ![MS Word Windows](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/c941c45aa47784568731c2d2b3a33d8257ca0bd0.png)  
 ![MS Word macOS](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/1c06942a913c34949d2e0ffa21cee2878773f7b1.jpeg)

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [April 12, 2024, 2:45pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/7 "2024-04-12T14:45:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![marvinschmitt](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/marvinschmitt/32/98_2.png) [@marvinschmitt](https://discuss.bayesflow.org/u/marvinschmitt)\
**Post date:** [April 16, 2024, 5:54pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/8 "2024-04-16T17:54:59Z")

</div>

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`?

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [April 16, 2024, 8:21pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/9 "2024-04-16T20:21:11Z")

</div>

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.

 ![Screenshot 2024-04-16 at 4.09.59 PM](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/1683e4470f5c2dcafe27211480c5babe136f9a89.png)

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

---

<div class="post-metadata">

**Author:** ![marvinschmitt](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/marvinschmitt/32/98_2.png) [@marvinschmitt](https://discuss.bayesflow.org/u/marvinschmitt)\
**Post date:** [April 17, 2024, 8:00am UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/10 "2024-04-17T08:00:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [April 17, 2024, 3:22pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/11 "2024-04-17T15:22:13Z")

</div>

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

> **[Test](https://www.dropbox.com/scl/fo/v4xbs1jgqo9cqg40apu26/h?rlkey=yeemqt5h5yzhqle2ebwja6ccj&dl=0)**
>
> Shared with Dropbox

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):

 ![Screenshot 2024-04-17 at 11.17.13 AM](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/576b30f3e0557263c6fce8067f2a867431b2fc2e.png)

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:

 ![Screenshot 2024-04-17 at 11.20.24 AM](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/c65169cf4f9d19014fc47c4ec096269332f883a0.jpeg)

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

 ![Screenshot 2024-04-17 at 11.21.12 AM](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/6639f1cafcfc8191672ee2f43dcc6809bcfbe748.jpeg)

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

Thank you both!  
Ali

---

<div class="post-metadata">

**Author:** ![elseml](https://yyz1.discourse-cdn.com/flex007/user_avatar/discuss.bayesflow.org/elseml/32/19_2.png) [@elseml](https://discuss.bayesflow.org/u/elseml)\
**Post date:** [April 18, 2024, 7:49am UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/12 "2024-04-18T07:49:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ali](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ali](https://discuss.bayesflow.org/u/ali)\
**Post date:** [April 18, 2024, 3:59pm UTC](https://discuss.bayesflow.org/t/graphs-in-vector-format-like-pdf-svg/69/13 "2024-04-18T15:59:39Z")

</div>

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:

 ![Screenshot 2024-04-18 at 11.35.29 AM](https://canada1.discourse-cdn.com/flex007/uploads/bayesflow/original/1X/ea4a69a4dde6c1f9f47bea27b3a5acd02d92f793.jpeg)

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
