How to plot 'nan' values for coordinates in shape.stim()


I’m inputting coordinates into my ShapeStim function using the vertices parameter. But my coordinates contain ‘nan’ values which I want to plot so I can see the missing section. But I get the following error:

OSError: exception: access violation reading 0xFFFFFFFFFFFFFFFF

So I was wondering how I can get psychopy to read the ‘nan’ value in my array of coordinates.

my coordinates look like this:

> my_coordinates = np.array([[ 0.04283395,-0.71760799],
>  [-0.02222347,-0.71235765],
>  [-0.08029895 ,-0.69315558],
> [nan, nan], 
> etc..
> ]])

I also get related error:

NameError: name ‘nan’ is not defined

Any help would be appreciated, thanks !

Please could you clarify what you want to happen?

The easiest option might be to replace nan with 0 which would highlight the missing coordinates.

Hi @wakecarter ,

I want to plot those nan values so that the image is drawn with those missing coordinates, e.g. if my original coordinates is length 64, then say 4 of those are nan values and it draws the image with those 4 coordinates missing from the image, so structural integrity of image is retained but those 4 coordinates don’t show up when I draw them on my window. I tried to input 0, but it makes the coordinate 0 so shape is distorted-which I don’t want. I’m plotting polygons with these coordinates

I can get the correct plot using matplotlib, which automatically (?) seems to plot the nan values, but I dont know how psychopy or rather shape.Stim can do this?

In that case what you need to do is strip out the nan values before plotting it.

You could cycle through the list and copy valid values to a second list which you plot.

Hi @wakecarter

Thanks for the suggestion,

I’ve tried it but it doesn’t seem to work, since those points just revert to 0 since I’m looping through an empty numpy array and keeping the same (64,2) dimensions. Is there a way I can adjust the lineColor then in the ShapeStim() parameter? so that only those missing/ nan coordinates become invisible?

I made a mistake in the original ShapeStim() argument. I forgot to set closeShape = False. It works now with plotting the np.nan values , Thanks !

1 Like