Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: Set the alpha value for plots in rcParams #5132

Closed
Jul3k opened this issue Sep 24, 2015 · 12 comments
Closed

ENH: Set the alpha value for plots in rcParams #5132

Jul3k opened this issue Sep 24, 2015 · 12 comments

Comments

@Jul3k
Copy link

Jul3k commented Sep 24, 2015

Using Matplotlib 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)
plot(x,y3, 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

Could this be implemented so it can be set in a style sheet and the code stays short and readable?

@tacaswell tacaswell added this to the proposed next point release (2.1) milestone Sep 24, 2015
@tacaswell
Copy link
Member

You can do this by setting a the color/prop cycle to use colors which have an alpha component.

The traitlet overhaul will take care of this as well

@Jul3k
Copy link
Author

Jul3k commented Sep 24, 2015

Can i set the "axes.color_cycle" values in hex natation as e.g.:
"#ff0000b4"
Because when i try to do so i receive an exception of "invalid hex color string"

@WeatherGod
Copy link
Member

take out the pound sign because our rcfile reader is really naive and
always treats that as a comment symbol.

Also note that color_cycle is deprecated in the upcoming 1.5 release,
replaced with the more versatile "prop_cycle" mechanism. However, it will
likely be awhile before we actually remove "color_cycle".

On Thu, Sep 24, 2015 at 9:30 AM, Jul3k notifications@github.com wrote:

Can i set the "axes.color_cycle" values in hex natation as e.g.:
"#ff0000b4"
Because when i try to do so i receive an exception of "invalid hex color
string"


Reply to this email directly or view it on GitHub
#5132 (comment)
.

@Jul3k
Copy link
Author

Jul3k commented Sep 24, 2015

Without the pound sign i get a "to_rgb: Invalid rgb arg "ff0000b4"" error.
The exact call is:

plt.rcParams['axes.color_cycle'][0] = "ff0000b4"

matplotlib version 1.4.3

Without the alpha content ("b4") it works fine. It seams to me that the parser doese not accept 4 Byte hex color codes with alpha content. I could work around this by using the to_rgba builtin method

My workaround looks as follows:

to_rgba = matplotlib.colors.ColorConverter().to_rgba
for i, c in enumerate(plt.rcParams['axes.color_cycle']):
    plt.rcParams['axes.color_cycle'][i] = to_rgba(c,0.2)

@WeatherGod
Copy link
Member

Ah, indeed, our hex color spec parser is just rgb, not rgb[a]. Sounds like
an easy feature to implement, though...

On Thu, Sep 24, 2015 at 10:21 AM, Jul3k notifications@github.com wrote:

Without the pound sign i get a "to_rgb: Invalid rgb arg "ff0000b4"" error.
The exact call is:
plt.rcParams['axes.color_cycle'][0] = "ff0000b4"

matplotlib version 1.4.3

Without the alpha content ("b4") it works fine. It seams to me that the
parser doese not accept 4 Byte hex color codes with alpha content. I could
work around this by using the to_rgba builtin method

My working code looks as follows:
to_rgba = matplotlib.colors.ColorConverter().to_rgba
for i, c in enumerate(plt.rcParams['axes.color_cycle']):
plt.rcParams['axes.color_cycle'][i] = to_rgba(c,0.2)


Reply to this email directly or view it on GitHub
#5132 (comment)
.

@tacaswell
Copy link
Member

Pretty sure rcparams will take a 4-tuple an input

@Jul3k
Copy link
Author

Jul3k commented Sep 24, 2015

Yes rcparams takes a 4-tuple as an input. As @WeatherGod stated the problem was related to the fact that the color parser only checks for 3-Byte (#FFFFFF) color strings and does not understand 4-Byte (#FFFFFFAA) color strings with alpha channel. So the way i presented the color information was not suiteable to the parser

@tacaswell
Copy link
Member

@Jul3k Can you make a new issue to upgrade out hex parser to deal with RGBA hex codes?

@Jul3k
Copy link
Author

Jul3k commented Sep 24, 2015

I opend a new issue relating to the color spec parser

@WeatherGod
Copy link
Member

I think this is closed by #6382, which updated the parser to allow 4-byte hex strings. Re-open this issue if that isn't sufficient.

@JoElfner
Copy link

JoElfner commented Aug 6, 2020

I frequently need alpha independently of the color cycler. Most importantly I want different plots to have different default alphas, f.i. alpha=.5 for my scatter plots, while not using alpha for my line plots. Thus, as far as I can see, setting alpha to the color cycle is not working. Any change this is going to be implemented in the rcParams?

@timhoffm
Copy link
Member

timhoffm commented Aug 6, 2020

This is too specialized for rcParams, in particular if you want to have different values for scatter plots and line plots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants