jupyter-notebookplotly

Plotly chart not displayed in jupyter notebook


I want to generate and display plotly charts in a jupyter notebook but for reasons I don't understand, its not working. Here's my simple code:

import plotly.offline as pyo
import plotly.graph_objects as go

pyo.init_notebook_mode()

summary = {'text/csv': 2, 'application/json': 1}
summary = {'Apples': 30, 'Bananas': 45, 'Cherries': 25}

mimetypes = list(summary.keys())
counts = list(summary.values())

fig = go.Figure()

fig.add_trace(go.Bar(x=mimetypes, y=counts))

fig.update_layout(
    title='Fruit Count',
    xaxis_title='Fruit',
    yaxis_title='Count'
)

# Show plot
fig.show()

When I execute the cell it displays blank output:

enter image description here

Can anyone suggest why its not displaying anything?

Extra info:

google-api-python-client
google-auth-httplib2
google-auth-oauthlib
jupyter
plotly
pandas

(google packages are needed for something else, I only mention here for completeness)

anyio==4.4.0
argon2-cffi==23.1.0
argon2-cffi-bindings==21.2.0
arrow==1.3.0
asttokens==2.4.1
async-lru==2.0.4
attrs==23.2.0
Babel==2.15.0
beautifulsoup4==4.12.3
bleach==6.1.0
cachetools==5.3.3
certifi==2024.7.4
cffi==1.16.0
charset-normalizer==3.3.2
comm==0.2.2
debugpy==1.8.2
decorator==5.1.1
defusedxml==0.7.1
executing==2.0.1
fastjsonschema==2.20.0
fqdn==1.5.1
google-api-core==2.19.1
google-api-python-client==2.137.0
google-auth==2.32.0
google-auth-httplib2==0.2.0
google-auth-oauthlib==1.2.1
googleapis-common-protos==1.63.2
h11==0.14.0
httpcore==1.0.5
httplib2==0.22.0
httpx==0.27.0
idna==3.7
ipykernel==6.29.5
ipython==8.26.0
ipywidgets==8.1.3
isoduration==20.11.0
jedi==0.19.1
Jinja2==3.1.4
json5==0.9.25
jsonpointer==3.0.0
jsonschema==4.23.0
jsonschema-specifications==2023.12.1
jupyter==1.0.0
jupyter-console==6.6.3
jupyter-events==0.10.0
jupyter-lsp==2.2.5
jupyter_client==8.6.2
jupyter_core==5.7.2
jupyter_server==2.14.1
jupyter_server_terminals==0.5.3
jupyterlab==4.2.3
jupyterlab_pygments==0.3.0
jupyterlab_server==2.27.2
jupyterlab_widgets==3.0.11
MarkupSafe==2.1.5
matplotlib-inline==0.1.7
mistune==3.0.2
nbclient==0.10.0
nbconvert==7.16.4
nbformat==5.10.4
nest-asyncio==1.6.0
notebook==7.2.1
notebook_shim==0.2.4
numpy==2.0.0
oauthlib==3.2.2
overrides==7.7.0
packaging==24.1
pandas==2.2.2
pandocfilters==1.5.1
parso==0.8.4
pexpect==4.9.0
platformdirs==4.2.2
plotly==5.22.0
prometheus_client==0.20.0
prompt_toolkit==3.0.47
proto-plus==1.24.0
protobuf==5.27.2
psutil==6.0.0
ptyprocess==0.7.0
pure-eval==0.2.2
pyasn1==0.6.0
pyasn1_modules==0.4.0
pycparser==2.22
Pygments==2.18.0
pyparsing==3.1.2
python-dateutil==2.9.0.post0
python-json-logger==2.0.7
pytz==2024.1
PyYAML==6.0.1
pyzmq==26.0.3
qtconsole==5.5.2
QtPy==2.4.1
referencing==0.35.1
requests==2.32.3
requests-oauthlib==2.0.0
rfc3339-validator==0.1.4
rfc3986-validator==0.1.1
rpds-py==0.19.0
rsa==4.9
Send2Trash==1.8.3
setuptools==70.3.0
six==1.16.0
sniffio==1.3.1
soupsieve==2.5
stack-data==0.6.3
tenacity==8.5.0
terminado==0.18.1
tinycss2==1.3.0
tornado==6.4.1
traitlets==5.14.3
types-python-dateutil==2.9.0.20240316
tzdata==2024.1
uri-template==1.3.0
uritemplate==4.1.1
urllib3==2.2.2
wcwidth==0.2.13
webcolors==24.6.0
webencodings==0.5.1
websocket-client==1.8.0
widgetsnbextension==4.0.11

enter image description here


Solution

  • I seem to have fixed this by downgrading to python 3.11. These are the steps I took:

    I then open up my jupyter notebook. Interestingly I didn't have to re-run any cells, the chart was already present within the notebook. This means it was always in the notebook when using python 3.12, it just wasn't being displayed properly.

    screenshot of my notebook

    In case anyone is interested here are the versions of dependencies that have been installed:

    anyio==4.4.0
    argon2-cffi==23.1.0
    argon2-cffi-bindings==21.2.0
    arrow==1.3.0
    asttokens==2.4.1
    async-lru==2.0.4
    attrs==23.2.0
    Babel==2.15.0
    beautifulsoup4==4.12.3
    bleach==6.1.0
    cachetools==5.3.3
    certifi==2024.7.4
    cffi==1.16.0
    charset-normalizer==3.3.2
    comm==0.2.2
    debugpy==1.8.2
    decorator==5.1.1
    defusedxml==0.7.1
    executing==2.0.1
    fastjsonschema==2.20.0
    fqdn==1.5.1
    google-api-core==2.19.1
    google-api-python-client==2.137.0
    google-auth==2.32.0
    google-auth-httplib2==0.2.0
    google-auth-oauthlib==1.2.1
    googleapis-common-protos==1.63.2
    h11==0.14.0
    httpcore==1.0.5
    httplib2==0.22.0
    httpx==0.27.0
    idna==3.7
    ipykernel==6.29.5
    ipython==8.26.0
    ipywidgets==8.1.3
    isoduration==20.11.0
    jedi==0.19.1
    Jinja2==3.1.4
    json5==0.9.25
    jsonpointer==3.0.0
    jsonschema==4.23.0
    jsonschema-specifications==2023.12.1
    jupyter==1.0.0
    jupyter-console==6.6.3
    jupyter-events==0.10.0
    jupyter-lsp==2.2.5
    jupyter_client==8.6.2
    jupyter_core==5.7.2
    jupyter_server==2.14.2
    jupyter_server_terminals==0.5.3
    jupyterlab==4.2.3
    jupyterlab_pygments==0.3.0
    jupyterlab_server==2.27.2
    jupyterlab_widgets==3.0.11
    MarkupSafe==2.1.5
    matplotlib-inline==0.1.7
    mistune==3.0.2
    nbclient==0.10.0
    nbconvert==7.16.4
    nbformat==5.10.4
    nest-asyncio==1.6.0
    notebook==7.2.1
    notebook_shim==0.2.4
    numpy==2.0.0
    oauthlib==3.2.2
    overrides==7.7.0
    packaging==24.1
    pandas==2.2.2
    pandocfilters==1.5.1
    parso==0.8.4
    pexpect==4.9.0
    platformdirs==4.2.2
    plotly==5.22.0
    polars==1.1.0
    prometheus_client==0.20.0
    prompt_toolkit==3.0.47
    proto-plus==1.24.0
    protobuf==5.27.2
    psutil==6.0.0
    ptyprocess==0.7.0
    pure-eval==0.2.2
    pyasn1==0.6.0
    pyasn1_modules==0.4.0
    pycparser==2.22
    Pygments==2.18.0
    pyparsing==3.1.2
    python-dateutil==2.9.0.post0
    python-json-logger==2.0.7
    pytz==2024.1
    PyYAML==6.0.1
    pyzmq==26.0.3
    qtconsole==5.5.2
    QtPy==2.4.1
    referencing==0.35.1
    requests==2.32.3
    requests-oauthlib==2.0.0
    rfc3339-validator==0.1.4
    rfc3986-validator==0.1.1
    rpds-py==0.19.0
    rsa==4.9
    Send2Trash==1.8.3
    six==1.16.0
    sniffio==1.3.1
    soupsieve==2.5
    stack-data==0.6.3
    tenacity==8.5.0
    terminado==0.18.1
    tinycss2==1.3.0
    tornado==6.4.1
    traitlets==5.14.3
    types-python-dateutil==2.9.0.20240316
    typing_extensions==4.12.2
    tzdata==2024.1
    uri-template==1.3.0
    uritemplate==4.1.1
    urllib3==2.2.2
    wcwidth==0.2.13
    webcolors==24.6.0
    webencodings==0.5.1
    websocket-client==1.8.0
    widgetsnbextension==4.0.1
    

    I wrote the dependency list of each to text files and compared them, here's what it came back with:

    > diff 3.11.txt 3.12.txt 
    49c49
    < jupyter_server==2.14.2
    ---
    > jupyter_server==2.14.1
    74d73
    > setuptools==70.3.0
    112d111
    < typing_extensions==4.12.2
    121a121
    > 
    

    Seems to me the only significant difference is the python version.