0todd0000 / spm1d

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

Customizing plotting of SPM results #67

Closed bernard-liew closed 7 years ago

bernard-liew commented 7 years ago

Dear Todd,

How have you been? I wish to custom a SPM results plot to the journal's specification. For example, plotting the p-values the result shows "p = 0.004". Is there a way to remove the 0 before the decimal? Also the number of significant figures?

Many thanks for the help.

Regards, Bernard

0todd0000 commented 7 years ago

Hi Bernard,

It's not possible to change the default behavior of "plot_p_values", but you can customize using "pyplot.text" as follows...

If the inference results are saved in a variable called "spmi" then you can see all cluster-level p values in "spmi.p" and cluster centroids (and p values) in "spmi.clusters". So this command:

>>>  print( spmi.clusters[0] )

will produce something like this:

Cluster
   threshold       :  3.227
   centroid        :  (75.014, 3.535)
   isinterpolated  :  True
   iswrapped       :  False
   endpoints       :  (72.822, 77.247)
   extent          :  4.425
   extent (resels) :  0.16667
   height (min)    :  3.22704
   P               :  0.04441

Then you can place the p value where you want and format the string arbitrarily like this:

>>>  cluster = spmi.clusters[0]
>>>  p       = cluster.P
>>>  x,y     = cluster.centroid
>>>  pyplot.text( x + 10 , y - 5 , "%.5f" %p )

If you want to remove the leading zeros (before the decimal point) one way to do it is like this:

>>>  s = ( "%.5f" %p ).lstrip( "0" )
>>>  pyplot.text( x + 10 , y - 5 , s )

There's a discussion about formatting numbers with / without leading zeros here: http://stackoverflow.com/questions/10303797/print-floating-point-values-without-leading-zero

Regards, Todd

bernard-liew commented 7 years ago

Hi Todd,

Thanks for the help, that works...

Kind regards, Bernard