Closed bernard-liew closed 9 years ago
Hi Bernard,
It looks like "ax" is a list of axes objects. "ax.legend" will only work if "ax" itself is an axes object.
Try this:
>>> ax[0].legend()
or this:
>>> pyplot.legend()
Since "ax.legend" is a Matplotlib command and not an spm1d command you might get more detailed feedback from a Matplotlib forum: http://matplotlib.org http://stackoverflow.com/questions/tagged/matplotlib
Todd
Thanks Todd,
I found the command: it was
handles, labels = ax[i].get_legend_handles_labels()
ax[i].legend(handles, labels)
Bernard :)
Great, I'm glad it's working.
Dear Todd,
I have tried to copy some aspect of plotting from your example but couldn't get it to work as nicely as it should. Essentially, I wish to 1) add a legend which shows the label of a colored line e.g. red line = run; 2) Have an arrow that points to a significant cluster showing the p-value
My code is this (this is a loop):
ax = [0,0,0,0,0,0] pyplot.close('all') fig1 = pyplot.figure(figsize=(7,4)) for i in range(3): ax[i] = pyplot.subplot(2,3,i+1) spm1d_02.plot.plot_mean_sd(hip0[ang[i]],linecolor='k') #model 1(Cluster) spm1d_02.plot.plot_mean_sd(hip1[ang[i]],linecolor='b') #model 2(CUWA) pyplot.title(titles[i]) pyplot.ylabel('Angle') pyplot.ylim([-20,40]) ax[i].axhline() ax[i] = pyplot.subplot(2,3,i+4) hip_ti[i].plot() hip_ti[i].plot_threshold_label(fontsize=10) pyplot.ylabel('SPM{t}') pyplot.ylim([-8,8]) pyplot.tight_layout() pyplot.show()
I tried to add "ax.legend( loc='lower left', fontsize=9 )" for the legend, but it wouldn't pop out.
Looking forward to your input.
Bernard