Skip to content

a more user-friendly way to specify color for each arrow in 3D quiver? #8484

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
sytrus-in-github opened this issue Apr 14, 2017 · 6 comments
Closed
Labels
keep Items to be ignored by the “Stale” Github Action New feature topic: mplot3d
Milestone

Comments

@sytrus-in-github
Copy link

I wanted to visualize better the generated 3D quiver plot by specifiing a custom color for each arrow as follows:

vector3d(x, y, z) -> rgb(x/x_max, y/y_max, z/z_max) where all values are absolute values

After browsing the doc, I came across the colors argument which is passed to LineCollection.

After some trial and error, I finally figured out the logic of how the plot is actually drawn:

loop though the vectors to be drawn:
    if the norm of the vector is not 0 then:
        draw 1 line to represent the main part of the arrow ("-" part of "->")
loop again though the vectors to be drawn:
    if the norm of the vector is not 0 then:
        draw 2 lines to represent the head part of the arrow (">" part of "->")

For those who may be interested, for my case I have used the following functions as a work around to transform the list of rgb colors for each arrow to the corresponding list which correctly colored the 3D quiver plot:

def repeatForEach(elements, times):
    return [element for element in elements for _ in xrange(times)]
    
def renderColorsForQuiver3d(colors):
    # filter out 0-length vector corresponding to rgb=(0,0,0) that won't be drawn
    colors = filter(lambda x: x!=(0.,0.,0.), colors) 
    # set up rgb color for each lines of arrows
    return colors + repeatForEach(colors, 2) 

My question is: shouldn't it be more user-friendly to just specify a color for each arrow regardless of its length(a.k.a. whether it will actually be drawn)? I suppose the similar problem also exists for customizing other properties like line width.

Matplotlib version

tested with matplotlib 2.0.0, python 2.7 on windows 7 x64 and ubuntu 16.04 x64

@sytrus-in-github
Copy link
Author

See this gist for an example of specifying custom colors for each arrow.

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Apr 14, 2017
Copy link

github-actions bot commented Nov 3, 2023

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!

@github-actions github-actions bot added the status: inactive Marked by the “Stale” Github Action label Nov 3, 2023
@scottshambaugh scottshambaugh added the keep Items to be ignored by the “Stale” Github Action label Nov 27, 2023
@rcomer rcomer removed the status: inactive Marked by the “Stale” Github Action label Nov 28, 2023
@prusswan
Copy link

prusswan commented Apr 18, 2024

Incidentally, this issue is not present in much older versions of matplotlib, as seen in examples like https://github.com/pdebuyl/compute/blob/master/hilbert_curve/hilbert_curve.ipynb (version with images: http://pdebuyl.be/blog/2015/hilbert-curve.html)

Still happening in 3.6.x (or any version before 3.8.4)

@scottshambaugh
Copy link
Contributor

Does #27754 fix this issue?

@timhoffm
Copy link
Member

timhoffm commented May 4, 2024

I think so. Everybody, please report back if you think something is missing.

@timhoffm timhoffm closed this as completed May 4, 2024
@ysngshn
Copy link

ysngshn commented May 4, 2024

Great to see it finally fixed 🥳

@QuLogic QuLogic modified the milestones: future releases, v3.8.4 May 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
keep Items to be ignored by the “Stale” Github Action New feature topic: mplot3d
Projects
None yet
Development

No branches or pull requests

9 participants