在 Jupyter 笔记本中未显示 Plotly 旭日图

问题描述

我正在使用 Plotly 和 Jupyter 生成一些视觉效果,以更好地了解用户在线旅程.我正在使用 Plotly sunburst 图表,因为它为此目的提供了很好的视觉效果.Plotly 提供了一个效果很好的示例,并提供了我希望用我自己的数据生成的视觉效果.我创建了一个反映示例的数据框,但是当我尝试使用 .show() 时,没有生成图表.它似乎运行良好(没有错误)并在图表应该出现但不是图表的地方产生空白.我们测试的数据最终大约是 16K 行.

我玩过 Plotly 的在线和离线模式,但似乎都没有什么不同.我尝试了不同的标签和 ID.我也尝试过重新启动笔记本并只运行我的绘图而不是先运行示例.我已经把我的数据缩小到只有大约 50 行,有 4 个父节点和其余的死者.所有这些都得到了相同的结果,即出现绘图的空白,但没有生成绘图,也没有报告错误.

将 numpy 导入为 np将熊猫导入为 pd导入 plotly.graph_objectsdf3=pd.read_csv('sessionsForAnalysis.csv')df3['parents'] = df3.groupby(['sessionid'])['pagelabel'].shift(1)df4=df3[['pagelabel','pagelabel','parents']]df4.columns=["ids", "labels","parents"]df4=df4.drop_duplicates()fig1 = go.Figure()fig1.add_trace(go.Sunburst(ids=df4.ids,标签=df4.labels,父母=df4.parents,#values=one_dimensional_array, #我添加了这个域=dict(列=0)))fig1.show()

我希望这会产生一个如下所示的旭日形图,类似于

解决方案

我没有具体的解决方案,但至少在没有您的特定数据集的情况下尽我所能提出建议.

<小时>

我的第一个怀疑是您没有安装正确的软件包,但既然您已经声明了

<块引用>

我玩过 Plotly 的在线和离线似乎有所作为

在我看来,您的问题 是您的数据,特别是 类型 或 数据结构.来自

我的结论:确保 parents 中的每个观察都出现在 labels 中.

labels 中删除 'Noam' 是可以的.似乎是因为 'Noam' 没有出现在 parents 中:

从标签中删除 'Seth' 是不行的:

同样,请确保 parents 中的每个观察都出现在 labels 中,看看是否适合您.

I am using Plotly and Jupyter to generate some visuals to better understand user journeys online. I am using the Plotly sunburst chart since this makes a great visual for that purpose. Plotly provides an example that works great and provides the visual that I am looking to produce with my own data. I have created a dataframe that mirrors the example but when I try to use .show() no chart is produced. It appears to run fine (no errors) and produces white space where the chart should be but not chart. The data we are testing on ends up being about about 16K rows ultimately.

I have played around with the online vs offline for Plotly neither appeared to make a difference. I tried different labels and ID's. I have also tried restarting the notebook and only running my plot instead of the example first. I have taken my data and narrowed down to only about 50 lines with 4 parent nodes and the rest decedents. All of this got the same result of the white space appearing for the plot but no plot being produced and no errors reported.

import numpy as np                             
import pandas as pd
import plotly.graph_objects as go

df3=pd.read_csv('sessionsForAnalysis.csv')
df3['parents'] = df3.groupby(['sessionid'])['pagelabel'].shift(1)

df4=df3[['pagelabel','pagelabel','parents']]
df4.columns=["ids", "labels","parents"]
df4=df4.drop_duplicates()

fig1 = go.Figure()

fig1.add_trace(go.Sunburst(
    ids=df4.ids,
    labels=df4.labels,
    parents=df4.parents,
    #values=one_dimensional_array, #I added this
    domain=dict(column=0)
))



fig1.show()

I expect this to produce a sunburst plot like below, similar to the one found here except with our data so we can use it to analyze journeys:

解决方案

I don't have a specific solution, but at least a suggestion to the best of my abilities without your particular dataset.


My first suspicion was that you did not have the correct packages installed, but since you've stated that

I have played around with the online vs offline for Plotly neither appeared to make a difference

it seems to me that your problem has to be your data, specifically the type or the structure of your data. From your referred example I tried replacing values=[10, 14, 12, 10, 2, 6, 6, 4, 4] with values=['10', '14', '12', '10', '2', '6', '6', '4', '4'], but that worked just fine and increases the probability that it's the structure and not type that causes the problems.

Then I messed with the structure, replacing labels=["Eve", "Cain", "Seth", "Enos", "Noam", "Abel", "Awan", "Enoch", "Azura"] with labels=["Eve", "Cain", "Noam", "Abel", "Awan", "Enoch", "Azura"]. Now, no plot is produced with no error messages like this:

My conclusion: Make sure that each observation in parents occurs in labels.

Removing 'Noam' from labels is ok. seemingly because 'Noam' does not occur in parents:

Removing 'Seth' from labels is not ok:

So again, make sure that each observation in parents occurs in labels and see if that works out for you.

相关文章