I am new to plotly in python. I am trying to create the Sankey plot. The idea is to show the change ofsize of each Topic month on month. This is my pandas sample DataFrame. There are more Topic and also each Topic has more month and year. That makes the dataframe tall.
df
year month Topic Size
1 2022 1 1.0 40
2 2022 1 2.0 36
3 2022 1 3.0 70
4 2022 1 4.0 42
5 2022 1 5.0 25
6 2022 1 6.0 48
7 2022 2 1.0 14
8 2022 2 2.0 34
9 2022 2 3.0 39
10 2022 2 4.0 210
11 2022 2 5.0 106
12 2022 2 6.0 70
13 2022 3 1.0 47
14 2022 3 2.0 45
15 2022 3 3.0 78
16 2022 3 4.0 114
17 2022 3 5.0 84
18 2022 3 6.0 78
19 2022 4 1.0 42
20 2022 4 2.0 45
21 2022 4 3.0 78
22 2022 4 4.0 28
23 2022 4 5.0 74
24 2022 4 6.0 44
25 2022 5 1.0 57
26 2022 5 2.0 45
27 2022 5 3.0 82
28 2022 5 4.0 94
29 2022 5 5.0 54
30 2022 5 6.0 24
I have prepared the following from plotly demo. Ideally, source_node should be month1 and month2, month3, month4 should be intermittent nodes. month5 is the target node. All the topics will flow across the months. I am missing how to create variables node_label, source_node, target_node so that the following code works. I am not getting the correct plot output
node_label = ?
source_node = ?
target_node = ?
values = df['Size']
from webcolors import hex_to_rgb
%matplotlib inline
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
import plotly.graph_objects as go # Import the graphical object
fig = go.Figure(
data=[go.Sankey( # The plot we are interest
# This part is for the node information
node = dict(
label = node_label
),
# This part is for the link information
link = dict(
source = source_node,
target = target_node,
value = values
))])
# With this save the plots
plot(fig,
image_filename='sankey_plot_1',
image='png',
image_width=5000,
image_height=3000)
# And shows the plot
fig.show()