'Python - plotly chart rendered as *.png in jupyter notebook

I want to create some plots in jupyter notebook using plotly, but they do not show up when I set the renderer as "png". I have all the dependencies installed (Kaleido and Orca).

kaleido-core              0.2.1                h8ffe710_0    conda-forge

and

Name: orca
Version: 1.6

When I change the renderer to any other, which is not a static image it does work. But I want it to be "png" so I can upload the whole notebook to github and it will show the charts.

Below code I use. Imports:

import pandas as pd
import numpy as np
import plotly.graph_objects as go
import plotly.express as px
import plotly.io as pio
pio.renderers.default = "png"

And the chart:

_ = px.bar(train_data, y="Property_Area", title="Properties")
_.show()

When I delete the line about "renderers" it shows all right. But I want it to be static.

With renderer as "png" (or any other static image) it is loading indefinitely.



Solution 1:[1]

Based on here and my knowledge of Orca from the past, the idea is you export the static image. If you then want to see the static image inside the notebook, you can view it using code, like at the bottom here or view the image in a markdown cell where you can have more options for formatting size.

(Ignore that I had it render the interactive version normally earlier in the linked notebook. But note by hovering over the points that the earlier render is interactive in nbviewer!!! At Github you have no indication that there is even a plot there.)

Please see my comment below the OP, to use nbviewer when you are viewing or sharing notebooks. It provides the most full-featured way to view 'static' notebooks. I put static in quotes because via nbviewer javascript that is embedded still works so that several types of interactive objects, like Plotly plots, get rendered correctly & remain interactive.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1