# Center plotly figure

**URL:** <https://community.plotly.com/t/center-plotly-figure/39260>\
**Category:** 📊 Plotly Python\
**Created:** [May 11, 2020, 9:53pm UTC](https://community.plotly.com/t/center-plotly-figure/39260 "2020-05-11T21:53:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tud7](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@tud7](https://community.plotly.com/u/tud7)\
**Post date:** [May 11, 2020, 9:53pm UTC](https://community.plotly.com/t/center-plotly-figure/39260/1 "2020-05-11T21:53:19Z")

</div>

Is there a easy way for me to center my figure? When I use jupyter-nbconvert to convert to html, the figure is aligned on the right.

My code looks like this

```auto
fig = make_subplots(specs=[[{'secondary_y': True}]]) # I WANT TO CENTER THIS FIGURE
 
fig.add_trace(go.Bar(...))
 
fig.add_trace(go.Scatter...(),
              secondary_y="True")

fig.update_layout(
    title='My Plot', 
    barmode='overlay', 
    plot_bgcolor='rgb(245,245,245)',
    legend=dict(
        x=0.02,
        y=0.95),
    margin=dict(t=0, b=0, l=0, r=0)
)

```

Thanks

---

<div class="post-metadata">

**Author:** ![Emmanuelle](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/emmanuelle/32/7853_2.png) [@Emmanuelle](https://community.plotly.com/u/Emmanuelle)\
**Post date:** [May 12, 2020, 7:35am UTC](https://community.plotly.com/t/center-plotly-figure/39260/2 "2020-05-12T07:35:04Z")

</div>

Hi @tud7 welcome to the forum! Could you please attach screenshots to show what the problem is? With the zero margin which you are setting the figure (ie the axes domain) should be centered.

---

<div class="post-metadata">

**Author:** ![tud7](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@tud7](https://community.plotly.com/u/tud7)\
**Post date:** [May 12, 2020, 5:35pm UTC](https://community.plotly.com/t/center-plotly-figure/39260/3 "2020-05-12T17:35:34Z")

</div>

Thank you!!!

You can see the plot is all the way to the left compared to the markdown. The markdown text is right-aligned.  
It looks fine inside jupyter-notebook, but not in the generated html

I run the following command to convert to html:

```auto
jupyter-nbconvert --execute --no-input $IPYNB_FILE

```

 ![Capture](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/1/1ab0ddd6aacbb4abb73fb3ce3458fbf1e07b1700.png)

**-----**

 ![Capture](https://us1.discourse-cdn.com/flex024/uploads/plot/original/2X/a/a8f48d4203bbab2c22f5aba5e466e09dc3cb386e.png)

---

<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:** [May 12, 2020, 6:01pm UTC](https://community.plotly.com/t/center-plotly-figure/39260/4 "2020-05-12T18:01:02Z")

</div>

Hi @tud7

Please see the link from this old answer (2017): [Centering Plotly Output on Jupyter Notebook](https://community.plotly.com/t/centering-plotly-output-on-jupyter-notebook/3049/2). I’m not sure if this method is still valid.

---

<div class="post-metadata">

**Author:** ![tud7](https://avatars.discourse-cdn.com/v4/letter/t/f6c823/32.png) [@tud7](https://community.plotly.com/u/tud7)\
**Post date:** [May 12, 2020, 11:18pm UTC](https://community.plotly.com/t/center-plotly-figure/39260/5 "2020-05-12T23:18:33Z")

</div>

Before I post this question, I saw that… but unfortunately, it does not work. I think the css class has changed.

---

<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:** [May 13, 2020, 4:48am UTC](https://community.plotly.com/t/center-plotly-figure/39260/6 "2020-05-13T04:48:10Z")

</div>

Hi @tud7,

In this case it’s better to address your question on Jupyter discourse, section Q&A:  
[https://discourse.jupyter.org/c/questions/18](https://discourse.jupyter.org/c/questions/18).
