Matplotlib: set title color in stylesheet

I am setting a custom stylesheet in mpl. I found and changed some parameters on the Internet:

axes.titlesize : 18 axes.labelsize : large axes.labelcolor : ffffff 

I also want to change the font color of the header. Of these settings, axes.titlecolor seemed like a good guess, but it didn't work. Any ideas how to do this?

+8
python matplotlib
source share
3 answers

I am not completely familiar with how the Mpl style sheets actually execute, but I assume that they just previously edited the mpl rc files.

If they are really mpl-rc files, then based on reading through the current current rc file in the "Axis" there is no color in the header.

My job of adding stylistic functions that may or may not be implemented in rc files does something like:

 using_custom_style = true plt.use('my_style') ... if using_custom_style: ax.set_title('my title', color=my_color_of_choice) else: ax.set_title('my_title') # this doesn't specify a color so it will just use whatever default vaule mpl knows to use 

This is not the best workaround, as it adds a lot of noise to the code, but this is the only thing I found to work when I cannot figure out where the default value is really stored in the mpl files or parameter tables.

analyzing the mpl rc file, if you run something like "grep title matplotlibrc", it spits out only the instances it finds in the name of the word:

# size of special ticks: tags, axes, tags, title, etc., see rc

# axes.titlesize: large # font of axis name

therefore, there is no default setting for the header, or rather, if there is one called something else that is not directly obvious

'grep color matplotlibrc' displays all instances of the word color in the rc file

Again, there seems to be nothing directly related to the title color or the default text color.

Looking a little closer to the Mpl API, axes.set_title () accepts kwargs such as color =, which are simply flagged as valid Text properties.

http://matplotlib.org/1.4.3/api/text_api.html#matplotlib.text.Text lists the valid text properties. For color, all he says is "any color matplotlib"

I would suggest that somewhere in the mpl source code there is a line that processes what to do if the kwarg color is not specified for this Text object. Somewhere there is a default color, which I think is probably just "k". However, it is not clear to me how to change this setting.

Sorry for the long discourse, hope this helps some.

+2
source share

Maybe the bit will answer later, but in any case) If you want to change the default name color, you can set the text.color property in the matplotrc file (black by default). Of course, this will change the colors of all your text outputs.

+2
source share

It may work (Refrenced From Here)

 title_obj = plt.title('my random fig') plt.getp(title_obj) plt.getp(title_obj, 'text') plt.setp(title_obj, color='r') #Sets it to the color red 
-one
source share

All Articles