Nilearn plotting.plot_stat_map control title properties

nilearn

#1

Dear friends and experts,

I am trying to control the properties of a title that I want to place on plotting.plot_stat_map()

display = plotting.plot_stat_map(plot_img,
                                         bg_img=baseimg,
                                         title=dict(text=condition_labels[condI],
                                                    color=str_color,
                                                    bgcolor='w'),
                                         vmax=maxt,
                                         display_mode='z',
                                         axes=ax[cond],
                                         colorbar=True,
                                         black_bg=False,
                                         annotate=False,
                                         draw_cross=False,
                                         figure=fig,
                                         cut_coords=coords)

I am trying to pass in a dict in title as you can see above, hoping that these properties, like ‘color’, ‘bgcolor’, etc, will get propagated in displays.py in title(), but unfortunately, my dictionary ends up being displayed as a string on the figure.

Is there a way to control these text color, text bgcolor, etc from the top, or is it not possible?

Do I need to define an if in display.title (just after the doc string) like such:

if isinstance(text, dict):
            """
            text passed in as a dictionary, unwrap
            """
            color = text['color']
            bgcolor = text['bgcolor']
            text = text['text']

many thanks for your help!

ian


#2

sorry, slow morning for me.

of course the answer is simple

display = plotting.plot_stat_map(plot_img,
                                         bg_img=baseimg,
                                         vmax=maxt,
                                         display_mode='z',
                                         axes=ax[cond],
                                         colorbar=True,
                                         black_bg=False,
                                         annotate=False,
                                         draw_cross=False,
                                         figure=fig,
                                         cut_coords=coords)

display.title(text=condition_labels[condI],
                   color=str_color,
                   bgcolor='w')


#3

Indeed. That’s the correct solution. Glad that you found it.