alfonsosemeraro / pyplutchik

Python visualisation for Plutchik annotated corpora.
65 stars 12 forks source link

error #10

Open cdlhao opened 1 year ago

cdlhao commented 1 year ago

from pyplutchik import plutchik

emotions = {'joy': 0.6, 'trust': 0.4, 'fear': 0.1, 'surprise': 0.7, 'sadness': 0.1, 'disgust': 0.5, 'anger': 0.4, 'anticipation': 0.6}

plutchik(emotions)

got following errors

IndexError Traceback (most recent call last) ~\AppData\Local\Temp/ipykernel_5468/15410483.py in 10 'anticipation': 0.6} 11 ---> 12 plutchik(emotions)

~\anaconda3\lib\site-packages\pyplutchik\pyplutchik.py in plutchik(scores, ax, font, fontweight, fontsize, show_coordinates, show_ticklabels, highlight_emotions, show_intensity_labels, ticklabels_angle, ticklabels_size, height_width_ratio, title, title_size, normalize) 1282 1283 # Draw inner white circle -> 1284 _neutral_central_circle(ax) 1285 1286

~\anaconda3\lib\site-packages\pyplutchik\pyplutchik.py in _neutral_central_circle(ax, r) 431 """ 432 c = sg.Point(0, 0).buffer(r) --> 433 ax.add_patch(descartes.PolygonPatch(c, fc='white', ec=(.5, .5, .5, .3), alpha=1, zorder = 15)) 434 435 return ax

~\anaconda3\lib\site-packages\descartes\patch.py in PolygonPatch(polygon, kwargs) 85 86 """ ---> 87 return PathPatch(PolygonPath(polygon), kwargs)

~\anaconda3\lib\site-packages\descartes\patch.py in PolygonPath(polygon) 60 "A polygon or multi-polygon representation is required") 61 ---> 62 vertices = concatenate([ 63 concatenate([asarray(t.exterior)[:, :2]] + 64 [asarray(r)[:, :2] for r in t.interiors])

~\anaconda3\lib\site-packages\descartes\patch.py in (.0) 61 62 vertices = concatenate([ ---> 63 concatenate([asarray(t.exterior)[:, :2]] + 64 [asarray(r)[:, :2] for r in t.interiors]) 65 for t in polygon])

IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed

cdlhao commented 1 year ago

the platform is Anaconda3-2021.11-Windows-x86_64

cdlhao commented 1 year ago

Plz check the reason thanks.

NicoAlvear commented 1 year ago

I had the same issue. Created a new env. Installed the specific versions in the requirements and it worked without problems.

alfonsosemeraro commented 1 year ago

Hello!

Sorry for my ultra late reply. Thank you @NicoAlvear for helping. @cdlhao do you still have troubles with the library?

pahalie commented 1 year ago

@alfonsosemeraro I just installed the library and have the issue above. `>>> emotions = {'joy': 0.6, ... 'trust': 0.4, ... 'fear': 0.1, ... 'surprise': 0.7, ... 'sadness': 0.1, ... 'disgust': 0.5, ... 'anger': 0.4, ... 'anticipation': 0.6}

plutchik(emotions) Traceback (most recent call last): File "", line 1, in File "/home/pp/anaconda3/envs/playground/lib/python3.8/site-packages/pyplutchik/pyplutchik.py", line 1284, in plutchik _neutral_central_circle(ax) File "/home/pp/anaconda3/envs/playground/lib/python3.8/site-packages/pyplutchik/pyplutchik.py", line 433, in _neutral_central_circle ax.add_patch(descartes.PolygonPatch(c, fc='white', ec=(.5, .5, .5, .3), alpha=1, zorder = 15)) File "/home/pp/anaconda3/envs/playground/lib/python3.8/site-packages/descartes/patch.py", line 87, in PolygonPatch return PathPatch(PolygonPath(polygon), **kwargs) File "/home/pp/anaconda3/envs/playground/lib/python3.8/site-packages/descartes/patch.py", line 62, in PolygonPath vertices = concatenate([ File "/home/pp/anaconda3/envs/playground/lib/python3.8/site-packages/descartes/patch.py", line 63, in concatenate([asarray(t.exterior)[:, :2]] + IndexError: too many indices for array: array is 0-dimensional, but 2 were indexed `

alfonsosemeraro commented 1 year ago

Hello @pahalie,

There must have been an update with either shapely or descartes. I can't figure out how to fix it right now, but I know for sure that older versions of shapely/descartes work well.

A temporary solution would be the one provided by @NicoAlvear: just open a new virtual environment and install the exact versions of the packages as listed in requirements.txt

I will work on fixing it asap, but I can't promise I'll be super quick.

Alfonso

charquero commented 1 year ago

Hi,

I'm experiencing the same problem as @NicoAlvear and @pahalie, but I have tried installing the older versions of shapely and descartes and the problem persists. Is there another way to get around this issue?

alfonsosemeraro commented 1 year ago

Hello @charquero, I'm sorry to hear this. Can you report exactly what package versions you have installed on your virtualenv?

innkbamboo commented 1 year ago

Hey @alfonsosemeraro, I'm having the same issue. My python version is 3.8.16 with

Tried to install version in requirement.txt, but got errors with shapely and numpy when installing.

innkbamboo commented 1 year ago

Hey @alfonsosemeraro, I'm having the same issue. My python version is 3.8.16 with

  • shapely [required: Any, installed: 2.0.1]
  • numpy [required: >=1.14, installed: 1.24.3]
  • matplotlib [required: Any, installed: 3.7.1]
  • descartes [required: Any, installed: 1.1.0]

Tried to install version in requirement.txt, but got errors with shapely and numpy when installing.

Tried other versions and found a working one for me:

esmarkowski commented 1 year ago

Here's a solution that worked for me. Modify your installation of descartes.

lib/python3.10/site-packages/descartes/patch.py

Around line 63 t.exterior should be t.exterior.coords

    vertices = concatenate([
        concatenate([asarray(t.exterior.coords)[:, :2]] +
                    [asarray(r)[:, :2] for r in t.interiors])
        for t in polygon])
ManueleVeggi commented 1 year ago

Hey @alfonsosemeraro, I'm having the same issue. My python version is 3.8.16 with

  • shapely [required: Any, installed: 2.0.1]
  • numpy [required: >=1.14, installed: 1.24.3]
  • matplotlib [required: Any, installed: 3.7.1]
  • descartes [required: Any, installed: 1.1.0]

Tried to install version in requirement.txt, but got errors with shapely and numpy when installing.

Tried other versions and found a working one for me:

* Name: numpy, Version: 1.23.4

* Name: Shapely, Version: 1.8.5.post1

* Name: matplotlib, Version: 3.6.0

* Name: descartes, Version: 1.1.0

This solution worked for me too! Thank you very much!

Arinbjarnar commented 1 year ago

Here's a solution that worked for me. Modify your installation of descartes.

lib/python3.10/site-packages/descartes/patch.py

Around line 63 t.exterior should be t.exterior.coords

    vertices = concatenate([
        concatenate([asarray(t.exterior.coords)[:, :2]] +
                    [asarray(r)[:, :2] for r in t.interiors])
        for t in polygon])

Thanks, @esmarkowski. I applied your solution, and it works like a charm. It saves me from installing specific versions of the impacted libraries. Ideally, we shouldn't edit a third-party library like that. However, I dug into the descartes/patch.py code to see what was happening. It is a Descartes object that is throwing the error. It's not the PyPlutchik code, so I expect they will fix the Descartes code eventually. I avoid version-specific issues in my code to make updating to the latest versions easier. It's not always possible, but it's so worthwhile. You may want to point it out to Descartes.

bhaskatripathi commented 1 year ago

Works by using : pip install numpy==1.23.4 Shapely==1.8.5.post1 matplotlib==3.6.0 descartes==1.1.0

marcolardera commented 5 months ago

Works by using : pip install numpy==1.23.4 Shapely==1.8.5.post1 matplotlib==3.6.0 descartes==1.1.0

I had the same issue and solved it using this exactly versions.

However, the package shoud be considered broken. @alfonsosemeraro Are you planning to update it in the near future? Do you need help?