# Save Arviz plots

**URL:** <https://discourse.pymc.io/t/save-arviz-plots/4805>\
**Category:** Questions\
**Created:** [April 5, 2020, 4:58am UTC](https://discourse.pymc.io/t/save-arviz-plots/4805 "2020-04-05T04:58:02Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jtrakk](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jtrakk](https://discourse.pymc.io/u/jtrakk)\
**Post date:** [April 5, 2020, 4:58am UTC](https://discourse.pymc.io/t/save-arviz-plots/4805/1 "2020-04-05T04:58:02Z")

</div>

I want to save my Arviz plots. When I do `arviz.plot_trace()` I get a numpy array. I can use `matplotlib.pyplot.savefig(path)` but that’s pretty opaque – I never know which plots are being saved.

Is there a way to simply get a figure object from the trace plot, so I can save it with `figure.savefig`?

---

<div class="post-metadata">

**Author:** ![rosgori](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/rosgori/32/1077_2.png) [@rosgori](https://discourse.pymc.io/u/rosgori)\
**Post date:** [April 5, 2020, 6:34am UTC](https://discourse.pymc.io/t/save-arviz-plots/4805/2 "2020-04-05T06:34:34Z")

</div>

Since `arviz` uses `matplotlib`, to save a figure, you would have to use `matplotlib.pyplot.savefig()`. If you use the `bokeh` backend`, there is another way to save a figure: [https://docs.bokeh.org/en/latest/docs/user\_guide/export.html](https://docs.bokeh.org/en/latest/docs/user_guide/export.html)

---

<div class="post-metadata">

**Author:** ![ahartikainen](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/ahartikainen/32/34_2.png) [@ahartikainen](https://discourse.pymc.io/u/ahartikainen)\
**Post date:** [April 5, 2020, 1:55pm UTC](https://discourse.pymc.io/t/save-arviz-plots/4805/3 "2020-04-05T13:55:15Z")

</div>

One way is to access the figure object from the axis object. ArviZ uses one figure object per plot.

```
axes = az.plot_trace(...)
fig = axes.ravel()[0].figure
fig.savefig(...)

```

For bokeh you probably want to save a layout, (each axis is it’s own bokeh figure and they are bind together with layout object)

---

<div class="post-metadata">

**Author:** ![Christopher\_Jenness](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/christopher_jenness/32/4802_2.png) [@Christopher\_Jenness](https://discourse.pymc.io/u/Christopher_Jenness)\
**Post date:** [February 14, 2022, 10:54am UTC](https://discourse.pymc.io/t/save-arviz-plots/4805/4 "2022-02-14T10:54:59Z")

</div>

> For bokeh you probably want to save a layout

I’ve been struggling to figure out how to do this. Do you have an example?

---

<div class="post-metadata">

**Author:** ![OriolAbril](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/oriolabril/32/2497_2.png) [@OriolAbril](https://discourse.pymc.io/u/OriolAbril)\
**Post date:** [February 15, 2022, 1:25am UTC](https://discourse.pymc.io/t/save-arviz-plots/4805/5 "2022-02-15T01:25:36Z")

</div>

Assuming you want to export them as png, it would look like:

```auto
from bokeh.io import export_png
from bokeh.layouts import gridplot

export_png(gridplot(ax.tolist()), filename="filename.png")

```

which should work if `ax` is a numpy array of length \>1. For a more general thing you can try

```auto
if isinstance(ax, ndarray):
    if len(ax.shape) == 1:
        export_png(gridplot([ax.tolist()]), filename=pngfilename)
    else:
        export_png(gridplot(ax.tolist()), filename=pngfilename)
else:
    export_png(ax, filename=pngfilename)

```
