You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I met the same problem. And I think this error happens when the giving label list only contains one element. In your case, the left array only contains "Sin Anomalias", which causes the 'topEdge' cann't be defined. You can add " topEdge = labelWidths["top"] " under "if i == 0:"(line 286) block to solve this problem
if i == 0:
labelWidths["bottom"] = 0
labelWidths["top"] = labelWidths[side]
topEdge = labelWidths["top"] # you can add this commend here, then the script can successfully run
else:
bottomWidth = widths[labels[i - 1]]["top"]
weightedSum = aspect / 200 * df[side + "Weight"].sum()
labelWidths["bottom"] = bottomWidth + weightedSum
labelWidths["top"] = labelWidths["bottom"] + labelWidths[side]
topEdge = labelWidths["top"]
My dataframe:
Cerrada | Text Analytics | Cantidad | Correctas | Erroneas | Asertividad
-- | -- | -- | -- | -- | -- | -- | --
Sin Anomalias | CR | 103 | 71 | 32 | 68.932039
Sin Anomalias | FR | 223 | 81 | 142 | 36.322870
Sin Anomalias | NC | 295 | 257 | 38 | 87.118644
Sin Anomalias | SVP | 2186 | 2053 | 133 | 93.915828
Sin Anomalias | SA | 5946 | 5578 | 368 | 93.810965
Sin Anomalias | SD | 455 | 217 | 238 | 47.692308
Sin Anomalias | TC | 77 | 8 | 69 | 10.389610
Sin Anomalias | YR | 49 | 46 | 3 | 93.877551
My code:
import matplotlib.pyplot as plt
from pysankey import sankey
import matplotlib.pyplot as plt
from pysankey import sankey
weight = df['Asertividad'].values[1:].astype(float)
sankey(left=df['Cerrada'].values[1:], right=df['Text Analytics'].values[1:], rightWeight=weight, leftWeight=weight, aspect=20, fontsize=20)
plt.show() # to display
The error thrown:
UnboundLocalError Traceback (most recent call last)
in
4 weight = df['Asertividad'].values[1:].astype(float)
5
----> 6 sankey(left=df['Cerrada'].values[1:], right=df['Text Analytics'].values[1:], rightWeight=weight, leftWeight=weight, aspect=20, fontsize=20)
7
8 plt.show() # to display
~\AppData\Roaming\Python\Python37\site-packages\pysankey\sankey.py in sankey(left, right, leftWeight, rightWeight, colorDict, leftLabels, rightLabels, aspect, rightColor, fontsize, ax)
192 # Determine positions of left label patches and total widths
193 leftWidths, topEdge = _get_positions_and_total_widths(
--> 194 dataFrame, leftLabels, 'left', aspect)
195
196 # Determine positions of right label patches and total widths
~\AppData\Roaming\Python\Python37\site-packages\pysankey\sankey.py in _get_positions_and_total_widths(df, labels, side, aspect)
296 LOGGER.debug("%s position of '%s' : %s", side, label, labelWidths)
297
--> 298 return widths, topEdge
UnboundLocalError: local variable 'topEdge' referenced before assignment
Thanks in advance !!!
The text was updated successfully, but these errors were encountered: