-->

Plotly sunburst plot not showing in Jupyter notebo

2020-07-26 05:11发布

问题:

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:

回答1:

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.