Using Jupyther Notebooks i often find myself repeadily writing the following to change the alpha value of the plots:
plot(x,y1, alpha=.6)
plot(x,y2, alpha=.6)
...
I was hoping to find a matching value in the rcParameters to change to option globally like:
plt.rcParams['lines.alpha'] = 0.6 #not working
What is a possible workaround to change the alpha value for all plots?
Unfortunately, based on their How to entry:
If you need all the figure elements to be transparent, there is currently no global alpha setting, but you can set the alpha channel on individual elements.
So, via matplotlib there's currently no way to do this.
What I usually do for global values is define an external configuration file, define values and import them to the appropriate scripts.
my_conf.py
# Parameters:
# matplotlib alpha
ALPHA = .6
my_plots.py
import conf.py as CONF
plot(x,y1, alpha=CONF.ALPHA)
plot(x,y2, alpha=CONF.ALPHA)
This usually helps in keeping configuration separated and easy to update.
Answering my own question with help of the matplotlib team the following code will do the job by changeing the alpha value of the line colors globally:
alpha = 0.6
to_rgba = matplotlib.colors.ColorConverter().to_rgba
for i, col in enumerate(plt.rcParams['axes.color_cycle']):
plt.rcParams['axes.color_cycle'][i] = to_rgba(col, alpha)
Note: In matplotlib 1.5 color_cycle
will be deprecated and replaced by prop_cycle
The ability the set the alpha value over the rcParams has also been added to the wishlist for Version 2.1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With