Skip to content

Builtin function for multicolor/colormapped line #14584

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
KOLANICH opened this issue Jun 20, 2019 · 5 comments
Closed

Builtin function for multicolor/colormapped line #14584

KOLANICH opened this issue Jun 20, 2019 · 5 comments

Comments

@KOLANICH
Copy link

Currently in order to make a multicolor curve one has to not to use plot but do its work manually himself: https://matplotlib.org/3.1.0/gallery/lines_bars_and_markers/multicolored_line.html

It is bad. I guess plot should accept c argument the same way scatter accepts it.

@efiring
Copy link
Member

efiring commented Jun 23, 2019

It would take much more than just a 'c' argument; one needs the colormap, the norm, and the values being mapped. Note also that the 'x' and 'y' coordinates of N points along the line require N-1 values for the colors of the line segments between the consecutive points.
I'm sure we don't want to overload the 'plot' function with all this. It might make sense to have a new function that would encapsulate the functionality shown in the example you cite.

@KOLANICH
Copy link
Author

*m sure we don't want to overload the 'plot' function with all this. It might make sense to have a new function that would encapsulate the functionality shown in the example you cite.

It is fine if that function is called from plot internally.

@ImportanceOfBeingErnest
Copy link
Member

Functions in the matplotlib API should have a defined return object. plot returns a list of Line2D objects.
One could of course let it take a c argument (and all the other arguments needed) and let it return a list of differently colored lines. But that is highly inefficient; and we probably don't want to introduce such inefficient code.
Letting plot return a LineCollection would be a bad API; I think in general we try to avoid functions where the return type depends on some combination of input parameters.
Hence the only option is really to create a new method that creates and returns a LineCollection.

@timhoffm timhoffm changed the title matplotlib.pyplot.plot should accept c argument specifying a colormap for every point Builtin function for multicolor/colormapped line Jun 24, 2019
@anntzer
Copy link
Contributor

anntzer commented Jun 24, 2019

This was already discussed in #6040; I would suggest folding the two discussions together.

@efiring
Copy link
Member

efiring commented Jun 24, 2019

I'm closing this in favor of #6040. I don't think the discussion here to date adds anything new.

@efiring efiring closed this as completed Jun 24, 2019
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