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

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 as px

x_data = [1,2,3,4]
y_data = [1,4,9,16]

fig = px.scatter(x= x_data, y = y_data)

  • Message in IPython Console:

    File ~\Doutorado\Python\Feeders\ in grafico_dispersao
    fig = px.scatter(x= x_data, y = y_data)

    File ~\Anaconda3\lib\site-packages\plotly\ in scatter
    return make_figure(args=locals(), constructor=go.Scatter)

    File ~\Anaconda3\lib\site-packages\plotly\ in make_figure

    File ~\Anaconda3\lib\site-packages\plotly\ in apply_default_cascade
    x[1] for x in args[“template”].layout.colorscale.sequential

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


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

Hi @efremfer !

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

For the plot rendering you can take a look at the doc Displaying Figures in Python

hi @efremfer
Welcome to the community :wave:

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. It will help make your posts more readable and even easier to understand and respond to.

Hi @Skiks .

Answering your question, I used “plot(fig)” instead of “” 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.


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)

maybe you can try instead of plot(fig)

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

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

Hello @allsyntax.

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

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

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

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

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

Hi @allsyntax ,

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

fig = px.scatter(x= x_data, y = y_data)

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.

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:

  File "/usr/local/lib/python3.10/site-packages/plotly/express/", line 264, in line
    return make_figure(args=locals(), constructor=go.Scatter)
  File "/usr/local/lib/python3.10/site-packages/plotly/express/", 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, and I found this line a little confusing: at 981ace849c9749ff9e600a9f0ac1ac97b14c202d · plotly/ · GitHub
It seems only when title is not None, it is checking the args['template'].layout? Is it intended?