# Subplot titles disappearing when adding annotations

**URL:** <https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256>\
**Category:** 📊 Plotly Python\
**Created:** [August 6, 2017, 8:46pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256 "2017-08-06T20:46:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![WindChimes](https://avatars.discourse-cdn.com/v4/letter/w/96bed5/32.png) [@WindChimes](https://community.plotly.com/u/WindChimes)\
**Post date:** [August 6, 2017, 8:46pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/1 "2017-08-06T20:46:30Z")

</div>

I am creating two subplots, both scatter. Then I add two annotations.

The problem is that subplot titles aren’t shown, unless I remove the code for adding the annotations.

I use:

> fig = py.tools.make\_subplots(rows = 1, cols= 2, subplot\_titles = (“Original data”, “Log-transformed data”))
> 
> fig.append\_trace(trace1, 1, 1)  
> fig.append\_trace(trace2, 1, 2)
> 
> fig[“layout”].update(annotations = [  
> go.Annotation(  
> x = 0.5,  
> y = -0.2,  
> showarrow=False,  
> text=“Text”,  
> xref=“paper”,  
> yref=“paper”  
> ),  
> go.Annotation(  
> x = -0.05,  
> y = 0.15,  
> showarrow=False,  
> text=“Text”,  
> xref=“paper”,  
> yref=“paper”,  
> textangle=-90  
> )  
> ])

Why is this happening? How can I fix it?

Thanks.

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [August 7, 2017, 12:24am UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/2 "2017-08-07T00:24:44Z")

</div>

@WindChimes,  
`fig['layout']['annotations']`is a list. Hence you should extend that list, in order to preserve the annotations defined when the fig was created (particularly `subplot_titles`).

```
 fig['layout']['annotations'].extend( [
       go.Annotation(
      x = 0.5,
      y = -0.2,
      showarrow=False,
      text=“Text”,
      xref=“paper”,
      yref=“paper”
       ),
     go.Annotation(
     x = -0.05,
     y = 0.15,
    showarrow=False,
     text=“Text”,
    xref=“paper”,
    yref=“paper”,
    textangle=-90
  )])
```

---

<div class="post-metadata">

**Author:** ![mixy](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@mixy](https://community.plotly.com/u/mixy)\
**Post date:** [April 4, 2018, 2:46pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/3 "2018-04-04T14:46:33Z")

</div>

How do we classify while extending that the 1st annotation should be on the 1st subplot, and the second annotation to be on the second subplot?

When i do straight extend, both the annotations comes on the top subplot and the second subplot is blank?

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [April 4, 2018, 5:14pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/4 "2018-04-04T17:14:05Z")

</div>

@mixy Before choosing the annotation position you should inspect the domain for x and y-plot coordinates in each subplot, as it is explained in this notebook [https://plot.ly/~empet/14826](https://plot.ly/~empet/14826).

---

<div class="post-metadata">

**Author:** ![agplot](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@agplot](https://community.plotly.com/u/agplot)\
**Post date:** [October 31, 2018, 4:53pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/5 "2018-10-31T16:53:40Z")

</div>

@empet: does this still work? I am trying:

> fig[“layout”][“annotations”].extend(  
> dict(  
> x=-0.075,  
> y=0.45,  
> showarrow=False,  
> text=“testing”,  
> textangle=-90,  
> xref=“paper”,  
> yref=“paper”,  
> font=dict(color=“black”, size=18),  
> )  
> )

And getting the error:

> —\> 65 fig[“layout”][“annotations”].extend([  
> 66 dict(  
> 67 x=-0.075,
> 
> AttributeError: ‘tuple’ object has no attribute ‘extend’

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [October 31, 2018, 6:51pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/6 "2018-10-31T18:51:36Z")

</div>

@agplot, If you are running Plotly 3.+, the answer is negative. First you should define separately the list  
of annotations, i.e.:

```auto
annotations=[]
annotations.append({...})

```

or

```auto
annotations.extend([{...}, {...}])

```

and finally, update `fig.layout`:

```auto
fig.layout.annotations=annotations

```

---

<div class="post-metadata">

**Author:** ![agplot](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@agplot](https://community.plotly.com/u/agplot)\
**Post date:** [October 31, 2018, 7:04pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/7 "2018-10-31T19:04:28Z")

</div>

@empet, Thanks for your response. It is still not 100% clear how to get both the subplot titles and the new annotation.

Should I start by creating the subplot titles, then convert fig.layout.annotations to a list (instead of a tuple), and finally extend with my new annotation?

---

<div class="post-metadata">

**Author:** ![empet](https://avatars.discourse-cdn.com/v4/letter/e/977dab/32.png) [@empet](https://community.plotly.com/u/empet)\
**Post date:** [October 31, 2018, 7:16pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/8 "2018-10-31T19:16:04Z")

</div>

@agplot, You should proceed as follows:  
Don’t pass `subplot_titles` to `tls.make_subplotst()`.  
Then define `annotations` as I mentioned in the previous answer, where you include both annotations for titles, and other annotations you intended to add before as updates. When the lists of annotations is complete, then you update the `fig.layout` with:

`fig.layout.annotations=annotations`

---

<div class="post-metadata">

**Author:** ![agplot](https://avatars.discourse-cdn.com/v4/letter/a/c37758/32.png) [@agplot](https://community.plotly.com/u/agplot)\
**Post date:** [October 31, 2018, 7:54pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/9 "2018-10-31T19:54:47Z")

</div>

Hi @empet,

I found a decent workaround. I use `tls.make_subplots()` with `subplot_titles`. Then,

```
annotations = [a.to_plotly_json() for a in fig["layout"]["annotations"]]
annotations.append({...})
fig["layout"]["annotations"] = annotations

```

Thanks for working through this with me.

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [November 3, 2018, 2:06pm UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/10 "2018-11-03T14:06:18Z")

</div>

For future reference, another option you can use here is the `+=` operator.

```python
fig["layout"]["annotations"] += ({...},) # Note the trailing comma

```

-Jon

---

<div class="post-metadata">

**Author:** ![Alexboiboi](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/alexboiboi/32/6420_2.png) [@Alexboiboi](https://community.plotly.com/u/Alexboiboi)\
**Post date:** [November 4, 2018, 12:01am UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/11 "2018-11-04T00:01:58Z")

</div>

Hi there, I just encountered the same problem as mentioned in this thread but  
fig[“layout”][“annotations”] += [{…}]  
did not work for me but  
fig[“layout”][“annotations”] += ({…})

did

Greetings, Alex

---

<div class="post-metadata">

**Author:** ![jmmease](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/jmmease/32/3706_2.png) [@jmmease](https://community.plotly.com/u/jmmease)\
**Post date:** [November 4, 2018, 12:23am UTC](https://community.plotly.com/t/subplot-titles-disappearing-when-adding-annotations/5256/12 "2018-11-04T00:23:04Z")

</div>

Thanks, Alex! You’re right and I’ve updated by post above 🙂  
-Jon
