0todd0000 / spm1d

One-Dimensional Statistical Parametric Mapping in Python
GNU General Public License v3.0
61 stars 21 forks source link

Graph representations of 2x2 repeated measures ANOVA #74

Closed gabrielmoisan closed 6 years ago

gabrielmoisan commented 6 years ago

Hello, I'm looking for a source code (for Python) to help me illustrate the data before submitting my manuscript for publication. I have looked on this forum and on the spm1d.org website and have not found what I am looking for. I apologize if it is available and I just did not found it. I performed a 2x2 repeated-measures ANOVA. I want to create graphs with the mean of the variable on top and the F curve on the bottom of the figure. I read some of your papers and I liked the representation of the data (De Ridder et al., 2013, 2015). I would like to create something similar. Thank you for your help, Gabriel Moisan Université du Québec à Trois-Rivières, Canada

m-a-robinson commented 6 years ago

Hello Gabriel,

Producing good figures can certainly have a positive impact on a manuscript. For clarity, the figures in the papers you mention plot post-hoc t-test results rather than the "main effect" F curve (I appreciate in a 2*2 design this is not necessary).

To produce the 2*2 figure layout that you are after, you can use the pyplot.subplot function from Matplotlib - here are some simple examples.

If you want to see the code used for DeRidder et al., 2013 Figure 1 - see below. The code could be written more efficiently looping through the plots for example but this line by line response should give you a good idea about the level of customisation that can be used to make the figures to your taste.

The variables describing the groups are Y0, Y1 and Y2. I have also removed the old functions I used to annotate the p-values. This can just be done with matplotlib text if required.

Good luck! Regards Mark

# remember to use this in your code before creating the figures
from matplotlib import pyplot

#(3) Plot:
pyplot.close('all')
# Means and sds
pyplot.subplot(231)
line1,cloud1 = Y0.plot_mean_std(linecolor='k') #CAI
line2,cloud2 = Y1.plot_mean_std(linecolor='k') #CON
pyplot.title('CAI vs CON')
pyplot.setp(line1,linestyle='--') #Set line style of mean line
pyplot.setp(line2,linestyle='-') 
pyplot.setp(cloud1,linestyle='-',facecolor='#A6A6A6',alpha=0.5) #Set line style of sd cloud (alpha = transparency)
pyplot.setp(cloud2,linestyle='-',facecolor='#696969',alpha=0.5)
pyplot.ylabel(r'$\rm{Angle (^\circ)}$') # For symbols see http://matplotlib.org/users/mathtext.html?highlight=symbol
pyplot.xlabel('Stance Phase (%)')
pyplot.ylim([-20,5])
pyplot.text(5, 2.5, '(a)')

pyplot.subplot(232)
#pyplot.title('Rigid Foot')
line3,cloud3 = Y0.plot_mean_std(linecolor='k') #CAI
line4,cloud4 = Y2.plot_mean_std(linecolor='k') #COP
pyplot.title('Rigid Foot\nCAI vs COP')
pyplot.setp(line3,linestyle='--') 
pyplot.setp(line4,linestyle=':') 
pyplot.setp(cloud3,linestyle='-',facecolor='#A6A6A6',alpha=0.5)
pyplot.setp(cloud4,linestyle='-',facecolor='#E3E3E3',alpha=0.5)
pyplot.ylabel(r'$\rm{Angle (^\circ)}$')
pyplot.xlabel('Stance Phase (%)')
pyplot.ylim([-20,5])
pyplot.text(5, 2.5, '(b)')

pyplot.subplot(233)
line5,cloud5 = Y1.plot_mean_std(linecolor='k') #CON
line6,cloud6 = Y2.plot_mean_std(linecolor='k') #COP
pyplot.title('CON vs COP')
pyplot.setp(line5,linestyle='-') 
pyplot.setp(line6,linestyle=':') 
pyplot.setp(cloud5,linestyle='-',facecolor='#696969',alpha=0.5)
pyplot.setp(cloud6,linestyle='-',facecolor='#E3E3E3',alpha=0.5)
pyplot.ylabel(r'$\rm{Angle (^\circ)}$')
pyplot.xlabel('Stance Phase (%)')
pyplot.ylim([-20,5])
pyplot.text(5, 2.5, '(c)')

#plot SPM results:
pyplot.subplot(234)
ti_1.plot()
pyplot.xlabel('Stance Phase (%)')
pyplot.ylabel('SPM{t}')
pyplot.ylim([-4,4])
pyplot.text(5, 3.2, '(d)')

pyplot.subplot(235)
ti_2.plot()
pyplot.xlabel('Stance Phase (%)')
pyplot.ylabel('SPM{t}')
pyplot.ylim([-4,4])
pyplot.text(5, 3.2, '(e)')

pyplot.subplot(236)
ti_3.plot()
pyplot.xlabel('Stance Phase (%)')
pyplot.ylabel('SPM{t}')
pyplot.ylim([-4,4])
pyplot.text(5, 3.2, '(f)')

pyplot.tight_layout() # ensure no overlap
pyplot.show()