# AttributeError: 'NoneType' object has no attribute 'layout'

**URL:** <https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [May 18, 2023, 11:31pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393 "2023-05-18T23:31:34Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![efremfer](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@efremfer](https://community.plotly.com/u/efremfer)\
**Post date:** [May 18, 2023, 11:31pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/1 "2023-05-18T23:31:34Z")

</div>

Hi Guys.

I would be grateful if someone could help me with the problem below.

I´m trying to run the code below, but appeared an error only in the “debug mode” (“Ctrl + F10”) in Spyder IDE.  
Running the whole code (F5) and selection (F9) is working correctly.

- Spyder version: 5.4.3 (conda)
- Python version: 3.8.16 64-bit
- Operating System: Windows 10
- numpy v1.24.3
- plotly v5.14.1
- spyder v5.4.3

- Code Example:

import numpy as np  
import plotly.express as px

x\_data = [1,2,3,4]  
y\_data = [1,4,9,16]

fig = px.scatter(x= x\_data, y = y\_data)  
plot(fig)

- Message in IPython Console:

AttributeError: ‘NoneType’ object has no attribute ‘layout’

Thanks.

---

<div class="post-metadata">

**Author:** ![allsyntax](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/allsyntax/32/21613_2.png) [@allsyntax](https://community.plotly.com/u/allsyntax)\
**Post date:** [May 19, 2023, 12:09am UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/2 "2023-05-19T00:09:04Z")

</div>

I think it’s saying you need to add layout configs

---

<div class="post-metadata">

**Author:** ![Skiks](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/skiks/32/26561_2.png) [@Skiks](https://community.plotly.com/u/Skiks)\
**Post date:** [May 19, 2023, 12:32pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/3 "2023-05-19T12:32:34Z")

</div>

Hi @efremfer !

It is maybe a typo, but why are you using `plot(fig)` and not `fig.show()` ?  
(first time I see this syntax)

For the plot rendering you can take a look at the doc [Displaying Figures in Python](https://plotly.com/python/renderers/)

---

<div class="post-metadata">

**Author:** ![adamschroeder](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/adamschroeder/32/17280_2.png) [@adamschroeder](https://community.plotly.com/u/adamschroeder)\
**Post date:** [May 19, 2023, 1:17pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/4 "2023-05-19T13:17:15Z")

</div>

hi @efremfer  
Welcome to the community 👋

I’m confident that @allsyntax and @Skiks will be able to support you in finding an answer.

For any questions you ask in the future, I highly recommend you read over [this post](https://community.plotly.com/t/how-to-write-a-minimal-reproducible-example-mre/61502). It will help make your posts more readable and even easier to understand and respond to.

---

<div class="post-metadata">

**Author:** ![efremfer](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@efremfer](https://community.plotly.com/u/efremfer)\
**Post date:** [May 21, 2023, 6:31pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/5 "2023-05-21T18:31:46Z")

</div>

Hi @Skiks .

Answering your question, I used “plot(fig)” instead of “fig.show()” because the first struct did´nt show the plot in my web browser (chrome).

But the issue is when I run “fig = px.scatter(x= x\_data, y = y\_data)” in debug mode (Ctr + F10) that appear the error showed above.

Thanks.

---

<div class="post-metadata">

**Author:** ![efremfer](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@efremfer](https://community.plotly.com/u/efremfer)\
**Post date:** [May 21, 2023, 6:39pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/6 "2023-05-21T18:39:19Z")

</div>

Hi @allsyntax.

Thank you for your attention, but I dont have access to “layout”.

I only using o method sccater of library “plotly express” through the code below:

fig = px.scatter(x= x\_data, y = y\_data)

---

<div class="post-metadata">

**Author:** ![allsyntax](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/allsyntax/32/21613_2.png) [@allsyntax](https://community.plotly.com/u/allsyntax)\
**Post date:** [May 22, 2023, 2:11am UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/7 "2023-05-22T02:11:51Z")

</div>

maybe you can try `fig.show()` instead of `plot(fig)`

also try adding `template=None` to the end of your fig =px.scatter line

```auto
fig = px.scatter(x=x_data, y=y_data, template=None)

```

---

<div class="post-metadata">

**Author:** ![efremfer](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@efremfer](https://community.plotly.com/u/efremfer)\
**Post date:** [May 22, 2023, 11:54am UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/8 "2023-05-22T11:54:30Z")

</div>

Hello @allsyntax.

I tried the code plot(fig) and it works well. 🙂

HoweverI tried the parameter “template=None”, but **it did’nt work.** I have got the same error!! ☹

fig = px.scatter(x= x\_data, y = y\_data, template=None)

I don´t know what to do to solve this problem.

---

<div class="post-metadata">

**Author:** ![allsyntax](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/allsyntax/32/21613_2.png) [@allsyntax](https://community.plotly.com/u/allsyntax)\
**Post date:** [May 22, 2023, 12:17pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/9 "2023-05-22T12:17:10Z")

</div>

Ok, so maybe fig.show was all you needed and do not need to add template=None

---

<div class="post-metadata">

**Author:** ![efremfer](https://avatars.discourse-cdn.com/v4/letter/e/bc8723/32.png) [@efremfer](https://community.plotly.com/u/efremfer)\
**Post date:** [May 22, 2023, 4:43pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/10 "2023-05-22T16:43:22Z")

</div>

Hi @allsyntax ,

```
 I still have the error to be solved in the line code below.

```

fig = px.scatter(x= x\_data, y = y\_data)

---

<div class="post-metadata">

**Author:** ![allsyntax](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/allsyntax/32/21613_2.png) [@allsyntax](https://community.plotly.com/u/allsyntax)\
**Post date:** [May 23, 2023, 2:07am UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/11 "2023-05-23T02:07:24Z")

</div>

Maybe check and make sure you don’t have another variable or a module named `px`. But the code you posted seems fine on its own and should work. You might need to provide more context or try debugging to pinpoint where the issue is.

---

<div class="post-metadata">

**Author:** ![ry001](https://avatars.discourse-cdn.com/v4/letter/r/c67d28/32.png) [@ry001](https://community.plotly.com/u/ry001)\
**Post date:** [June 9, 2023, 7:49pm UTC](https://community.plotly.com/t/attributeerror-nonetype-object-has-no-attribute-layout/75393/12 "2023-06-09T19:49:15Z")

</div>

Hi, did you find any solution to this? I am experiencing the same error when plotting using `px.scatter` without any template.

The tracebacks I have are:

```auto
  File "/usr/local/lib/python3.10/site-packages/plotly/express/_chart_types.py", line 264, in line
    return make_figure(args=locals(), constructor=go.Scatter)
  File "/usr/local/lib/python3.10/site-packages/plotly/express/_core.py", line 2213, in make_figure
    elif args["template"].layout.margin.t is None:
AttributeError: 'NoneType' object has no attribute 'layout'

```

So to debug, I went to line 2213 of `plotly.express._core`, and I found this line a little confusing: [plotly.py/\_core.py at 981ace849c9749ff9e600a9f0ac1ac97b14c202d · plotly/plotly.py · GitHub](https://github.com/plotly/plotly.py/blob/981ace849c9749ff9e600a9f0ac1ac97b14c202d/packages/python/plotly/plotly/express/_core.py#L2220)  
It seems only when title is not None, it is checking the `args['template'].layout`? Is it intended?
