-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Simple function for multicolor line #6040
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
Comments
Please do not try to shoe-horn it into plot. There are already too much complexity / magic in that method. Instead of having a third set of |
Yup, I wouldn't want to touch
where |
Remember, we still support python 2.7, so required kwargs aren't available On Wed, Feb 24, 2016 at 2:35 AM, Antony Lee notifications@github.com
|
Yup, this is just to discuss the API, if we go this route we can always use kwargs-popping. |
I have an implementation of something like this over in MetPy. I'm not saying it's bullet proof, but I'll offer it as a starting point of the implementation: def colored_line(x, y, c, **kwargs):
"""Helper function to take a set of points and turn them into a collection of
lines colored by another array
Parameters
----------
x : array-like
x-axis coordinates
y : array-like
y-axis coordinates
c : array-like
values used for color-mapping
kwargs : dict
Other keyword arguments passed to :class:`matplotlib.collections.LineCollection`
Returns
-------
The created :class:`matplotlib.collections.LineCollection` instance.
"""
# Paste values end to end
points = concatenate([x, y])
# Exploit numpy's strides to present a view of these points without copying.
# Dimensions are (segment, start/end, x/y). Since x and y are concatenated back to back,
# moving between segments only moves one item; moving start to end is only an item;
# The move between x any moves from one half of the array to the other
num_pts = points.size // 2
final_shape = (num_pts - 1, 2, 2)
final_strides = (points.itemsize, points.itemsize, num_pts * points.itemsize)
segments = np.lib.stride_tricks.as_strided(points, shape=final_shape,
strides=final_strides)
# Create a LineCollection from the segments and set it to colormap based on c
lc = LineCollection(segments, **kwargs)
lc.set_array(c)
return lc Then again, maybe |
I would also add that there was some discussion about making a new python3 only module and this seems like a good candidate to be the first thing in there. |
I noticed that
mostly because it needs to create a bunch of |
Nevertheless, if you can find a more efficient way to accomplish the colored_line functionality, that would be great. You might be able to take advantage of path simplification in the case where there are too many data points for the available resolution. |
This issue has been marked "inactive" because it has been 365 days since the last comment. If this issue is still present in recent Matplotlib releases, or the feature request is still wanted, please leave a comment and this label will be removed. If there are no updates in another 30 days, this issue will be automatically closed, but you are free to re-open or create a new issue if needed. We value issue reports, and this procedure is meant to help us resurface and prioritize issues that have not been addressed yet, not make them disappear. Thanks for your help! |
A simple function for a multicolor line (à la http://matplotlib.org/examples/pylab_examples/multicolored_line.html) could be helpful, as the recipe is not that trivial. Shoehorning this into
plot
is probably going to be difficult, so I'd suggest something like(so that both line colors and marker colors can be set; the last line of properties provide defaults if only one of them has to be set, mostly for convenience).
Thoughts?
The text was updated successfully, but these errors were encountered: