-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Improve Gradient bar example #14057
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
Improve Gradient bar example #14057
Conversation
phi = direction * np.pi / 2 | ||
v = np.array([np.cos(phi), np.sin(phi)]) | ||
X = np.array([[v @ [1, 0], v @ [1, 1]], | ||
[v @ [0, 0], v @ [0, 1]]]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a style/judgment thing.
I think this is
np.dot(v, [[[1, 0], [1, 1]], [[0, 0], [1, 1]]]
or alternatively, just don't bother with dot products at all
s = np.sin(phi)
c = np.cos(phi)
X = [[s, s+c], [0, c]]
(either fully vectorize the thing, or don't vectorize it at all.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've chosen this notation intentionally to illustrate the projection of the corners on v.
The upper does not produce the same result (I assume it's some axis ordering, but didn't investigate). The lower does work, but obscures what the calculation actually does.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I didn't see it as a projection; indeed, that makes things clearer.
changed using the *transform* kwarg. | ||
direction : float | ||
The direction of the gradient. This is a number in | ||
range 0 (=vertical) to 1 (=horizontal). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just passing the angle (in degrees or in radians, up to you) seems simpler (in particular to explain)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be the angle only for square images. In general, it's a (nonlinear monotoneous) parametrization of the angle due to the distortion. I did not bother to untangle the transformation from extent
; and I didn't want to raise false expectations.
If you want to make real angles work, you are welcome to provide a PR. OTOH, maybe one does not want real angles - probably depends on the application. 0.5 is now always a gradient along the diagonal of the image.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, let's just leave it as it is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cute, just some minor nits.
…057-on-v3.1.x Backport PR #14057 on branch v3.1.x (Improve Gradient bar example)
PR Summary
AxesImage
.link to doc build