Skip to content

[ENH]: Add color argument to violinplot constructor #27298

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

Closed
landoskape opened this issue Nov 9, 2023 · 5 comments · Fixed by #27304
Closed

[ENH]: Add color argument to violinplot constructor #27298

landoskape opened this issue Nov 9, 2023 · 5 comments · Fixed by #27304
Milestone

Comments

@landoskape
Copy link
Contributor

Problem

It would be nice to specify the color of a set of violin plots in the constructor, rather than doing it afterwards for each component of the violinplot. This is usually how colors are set in matplotlib, so it would be in keeping with the general schema of matplotlib.

I can set this up as a PR if people think it's useful and makes sense for the library.

Proposed solution

The current color selection is done here. It looks like this:

        # Colors.
        if mpl.rcParams['_internal.classic_mode']:
            fillcolor = 'y'
            linecolor = 'r'
        else:
            fillcolor = linecolor = self._get_lines.get_next_color()

The proposed enhancement would look something like this, where color is a new key word argument with default value =None.

        # Colors.
        if mpl.rcParams['_internal.classic_mode']:
            fillcolor = 'y'
            linecolor = 'r'
        elif color is not None:
            fillcolor = linecolor = color 
        else:
            fillcolor = linecolor = self._get_lines.get_next_color()

This could even work for a sequence of colors, but a little bit more code would have to be changed.

@story645
Copy link
Member

story645 commented Nov 9, 2023

I think that's reasonable - if we support violin plot then we should support passing in colors.

@ksunden
Copy link
Member

ksunden commented Nov 9, 2023

I think we may want similar "facecolor"/"edgecolor"/"color(which is both)" logic from patches here. I also think that if given as a parameter, it should take precedence over the "classic mode" rc param, as you are explicitly asking for something deviating from default behavior then, and it is unexpected that it would be ignored.

@landoskape
Copy link
Contributor Author

I am working on a PR. I haven't contributed to Matplotlib before, so am noting locations where updates might be desired if the PR is accepted.

examples/statistics/customized_violin.py
galleries/plot_types/stats/violin.py
lib/matplotlib/tests/test_axes.py -- may want to add color testing here

And of course the "what's new", etc.

No comment needed until this finds it's way into a PR.

@landoskape
Copy link
Contributor Author

Closed, moving conversation to PR #27304

@ksunden
Copy link
Member

ksunden commented Nov 10, 2023

We typically keep issues open until a pr is merged, not just opened.

@ksunden ksunden reopened this Nov 10, 2023
@QuLogic QuLogic added this to the v3.11.0 milestone Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants