Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set tick egde color in matplotlib rc

I want to write a callable function that sets my matplotlib rc Parameters uniformly for all my different plots. So far it is just a block that I copy to every file and boils down to this:

import matplotlib as mpl

grey = '#808080'

mpl.rcParams['axes.linewidth'] = 0.3
mpl.rcParams['axes.edgecolor'] = grey

I am doing this to have thinner axes and to make my data stick out by having everything else a little grey-ish. But I cannot find a way to set the tick edge color to grey in the rc. I am looking for something like

'axes.tickedgecolor'

which doesn't seem to exist, sadly.

A way of doing it without rc is described here: Elegantly changing the color of a plot frame in matplotlib

I hope somebody can help, thanks!

Edit: Just to clarify: I found the option

mpl.rcParams['tick.color'] = '#808080'

but it also changes the tick labels, which I want to remain black!

like image 729
Ian Avatar asked Mar 15 '23 04:03

Ian


1 Answers

Okay, I found a little workaround to my answer that fulfills my needs:

import matplotlib as mpl

grey = '#808080'

mpl.rcParams['axes.linewidth'] = 0.3
mpl.rcParams['axes.edgecolor'] = grey
mpl.rcParams['xtick.color'] = grey
mpl.rcParams['ytick.color'] = grey
mpl.rcParams['axes.labelcolor'] = "black"

Although xtick.color also changes the label color, you can overwrite the label color afterwards.

Edit: Somehow this only works for a single plot. For a figure with 6 subplots it does not work.

Edit2: I couldn't get it to work with rcParams, so I changed the ticks during the subplotting routine

ax.tick_params('both', length=2, width=0.3, which='major', color=grey)

This made it work.

like image 58
Ian Avatar answered Mar 24 '23 17:03

Ian