Question & Answer
Question
以下のコードを使用して、Jupyter Notebookでは、Plotlyで作成したグラフを問題なく表示できました。しかしながら、 Jupyter Labでは同じコードを実行した場合は、Plotlyで作成したグラフは、空白として表示されました。
import plotly.express as px
fig = px.bar(x=["a", "b", "c"], y=[1, 3, 2])
fig.show()
Jupyter Labでは、Plotlyで作成したグラフを正しく表示できる方法を教えてください。
Cause
Plotlyの Figure オブジェクトを正しく表示するには、Jupyter Labで適切なレンダラーを設定する必要があります。
Answer
Plotly のドキュメントで説明されているように、以下のコードを使用して、iframeやcollabとしてPlotlyのデフォルト・レンダラーを明確的に設定する必要がありました。
import plotly.io as pio
pio.renderers.default = 'iframe' # or 'colab' or 'iframe' or 'iframe_connected' or 'sphinx_gallery'
[SAMPLE]
![image-20221227120239-1](https://www.ibm.com/support/pages/system/files/inline-images/image-20221227120239-1.png)
[{"Type":"MASTER","Line of Business":{"code":"LOB10","label":"Data and AI"},"Business Unit":{"code":"BU059","label":"IBM Software w\/o TPS"},"Product":{"code":"SSHE3N","label":"IBM Watson Studio Premium for IBM Cloud Pak for Data"},"ARM Category":[{"code":"a8m50000000L1dGAAS","label":"Analyze-\u003EModels-\u003ENotebooks"}],"ARM Case Number":"TS011252507","Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"All Versions"}]
Was this topic helpful?
Document Information
Modified date:
13 January 2023
UID
ibm16851841