Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

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

Merged
merged 1 commit into from
May 4, 2019

Conversation

timhoffm
Copy link
Member

@timhoffm timhoffm commented Apr 26, 2019

PR Summary

  • describe the mechanism how gradients can be created with AxesImage.
  • generalize the mechanism to allow gradients along arbitrary directions.
  • allow to select as subrange of a colormap for the gradient.
  • demonstrate how to reasonably use a gradient as an Axes background.

link to doc build

@timhoffm timhoffm added this to the v3.1.1 milestone Apr 27, 2019
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]]])
Copy link
Contributor

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.)

Copy link
Member Author

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.

Copy link
Contributor

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).
Copy link
Contributor

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)?

Copy link
Member Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@anntzer anntzer left a 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.

@anntzer anntzer merged commit 1f22f41 into matplotlib:master May 4, 2019
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request May 4, 2019
@timhoffm timhoffm deleted the example-gradient-bar branch May 4, 2019 16:08
dstansby added a commit that referenced this pull request May 4, 2019
…057-on-v3.1.x

Backport PR #14057 on branch v3.1.x (Improve Gradient bar example)
@QuLogic QuLogic modified the milestones: v3.1.1, v3.1.0 May 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.