0

So I am generating the interaction plot by using statsmodels package. Here in the figure below, you can see my current result.
I would like to have first "Block" and second "Alternating" in my x-axis. I was wondering how to make this change? Here is my code:

from statsmodels.graphics.factorplots import interaction_plot
import matplotlib.pyplot as plt
fig = interaction_plot(x=d['Group'], trace=d['Condition'], response=d['Asynch'],
    colors=['blue','yellow','green','gray'])
plt.rc("figure")
plt.rc('xtick', labelsize=24) 
plt.rc('ytick', labelsize=24)
plt.xlabel('Condition', fontsize=28)
plt.ylabel('IRI (ms)', fontsize=28)
sns.set(font_scale = 1.4)
plt. legend(loc='upper center', prop={'size': 24})
plt.legend(loc='upper right')
plt.ylabel("Asynchrony (ms)")
plt.show()
# plt.savefig('interaction.png', dpi=300)
fig.savefig('interaction.png', dpi=600)

and here is the result:
My interaction plot

  • Maybe making `group` categorical with a fixed order works here. Is `d` a pandas dataframe? – JohanC Dec 29 '21 at 11:02
  • Thank you, @JohanC! Yes, it is a pandas data frame. – Ali Rahimpour Dec 29 '21 at 22:28
  • So, does `d['Group'] = pd.Categorical(d['Group'], ["Block", "Alternating"])` work for your case? – JohanC Dec 29 '21 at 22:32
  • @JohanC I got an error using this. The error was _invalid syntax using from statsmodels.graphics.factorplots import interaction_plot_ . So I came up with a naive solution by changing the name of the categorical variables `\d['ord'] = ['1-Block' if v == 'Block' else '2-Alternating' for v in d['Group']]` and it works. Thank you, anyway! – Ali Rahimpour Dec 31 '21 at 00:11

0 Answers0