Search code examples
psychopy

how can I draw pie charts in PsychoPy Builder


I want to create half a pie chart to use in an existing builder script and I'm not sure how to go about it. (its actually to implement a speedometer)

Does anyone have any suggestions?

I realise I'll need to dip into some python code.

This old posting in Google Groups https://groups.google.com/forum/#!topic/psychopy-users/JcnS7ZtuVlM gives some sample code utilising pylab but they couldn't get it to work when it was dropped into Builder.

Thanks,


Solution

  • I've worked out how to do this now so here's my method for the record.

    # create 1st sector - use the **ori** parameter to control what bearing it 
    # starts on (0 is vertical)
    rad1 = visual.RadialStim( win=win, name='rad1', color=[1,-1,-1],
        angularCycles = 0, radialCycles = 0, radialPhase = 0.5, colorSpace = 'rgb', 
        ori= -90.0, pos=(0.5, -0.3), size=(0.3,0.3),  visibleWedge=(0.0, 135.0) )
    rad1.draw()
    
    #now draw another sector next to it by using **ori** again to line them up
    rad2 = visual.RadialStim( win=win, name='rad1', color=[-1,1,-1],
        angularCycles = 0, radialCycles = 0, radialPhase = 0.5, colorSpace = 'rgb', 
        ori= 45.0, pos=(0.5, -0.3), size=(0.3,0.3),  visibleWedge=(0.0, 45.0) )
    rad2.draw()
    

    This works fine in Builder, dropping it into a code segment and knowing that Builder uses a window called win

    Note that this uses the default mode for size (-1 to 1) so it will look different on different screen sizes. you may want to change to cm (and calibrate your monitor) if you want it to be round.

    Thanks to Jon P for his suggestion (via google groups) to use RadialStim)