# Can't move arviz legend

**URL:** <https://discourse.pymc.io/t/cant-move-arviz-legend/11984>\
**Category:** version agnostic\
**Tags:** arviz\
**Created:** [April 26, 2023, 5:59pm UTC](https://discourse.pymc.io/t/cant-move-arviz-legend/11984 "2023-04-26T17:59:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![davipatti](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/davipatti/32/5146_2.png) [@davipatti](https://discourse.pymc.io/u/davipatti)\
**Post date:** [April 26, 2023, 5:59pm UTC](https://discourse.pymc.io/t/cant-move-arviz-legend/11984/1 "2023-04-26T17:59:13Z")

</div>

Hello. I’m having trouble moving a legend in a plot generated in arviz. Say I have these two traces:

```python
import pymc as pm
import arviz as az 

with pm.Model():
    pm.Normal("a", 0, 1)
    trace1 = pm.sample()
    trace2 = pm.sample()

```

And I want to compare them with arviz:

```python
axes = az.plot_forest((trace1, trace2), combined=True)

```

![output](https://canada1.discourse-cdn.com/flex036/uploads/pymc3/original/2X/b/b4cae7dec7f992fa317d393a7f674579eb9a59df.png)

If I want to move the legend I would normally do:

```python
ax = axes[0]
handles, labels = ax.get_legend_handles_labels()
ax.legend(handles, labels, loc="upper left", bbox_to_anchor=(1, 1))

```

but `handles` and `labels` are both empty, so this doesn’t work

```python
print(handles, labels)

```

```python
[] []

```

(This is a toy example. I have a plot comparing 3 models with many variables where the legend gets put right in the middle of the plot which makes the plot unreadable).

Any help would be great, thanks!

I’m using arviz 0.15.1.

---

<div class="post-metadata">

**Author:** ![davidec00](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.pymc.io/davidec00/32/7071_2.png) [@davidec00](https://discourse.pymc.io/u/davidec00)\
**Post date:** [August 21, 2023, 11:20am UTC](https://discourse.pymc.io/t/cant-move-arviz-legend/11984/2 "2023-08-21T11:20:13Z")

</div>

I managed to solve this issue using the following code:

```auto
legend = ax[0].get_legend()
labels = [] if legend is None else [str(x._text) for x in legend.texts]
handles = [] if legend is None else legend.legend_handles

```

Solution found here: [Codereview question](https://codereview.stackexchange.com/questions/164381/matplotlib-get-legend-handles-labels-always-return-empty)
