Thanks to visit codestin.com
Credit goes to github.com

Skip to content

imshow transparency blend example #9254

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 3 commits into from
Oct 15, 2017
Merged

Conversation

choldgraf
Copy link
Contributor

Per a recent conversation on twitter, this is an example that shows off how you can blend transparency in with imshow when you're using a 2-D data matrix (as opposed to an image). A person was asking about how to do this on twitter, and as it's a common visualization in neuroscience I think it'd be helpful for people if they had an idea for how to get it done. I looked into supporting this with imshow directly, but it is not a trivial thing to do, so I figured documentation is the next best step. LMK what folks think.

@choldgraf choldgraf changed the title transparency blend example imshow transparency blend example Sep 30, 2017
Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this fails on 2.7.

I found the transparency effect to be pretty subtle, and wondered if an example could be created that had a different spatial pattern between the transparency and the underlying data.

I also found parts of the description and code could be described a bit more.

grid = np.array(np.meshgrid(xx, yy))
grid = grid.transpose(2, 1, 0)

# Generate the blobs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest specifying the expected data range of the raw blobs

# transparency with the image so that the extreme values are highlighted.
# We'll also add in contour lines to highlight the image values.

# Create an alpha channel based on weight values
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggest specifying that this means data with an absolute value below 0.00004 will get an alpha of 0.4 and that above 0.0010 will get an alpha value of 1. I had to spend a couple of minutes figuring out what these two lines do.

map. In this case, it's common to visualize the statistic of choice (e.g.,
a t-statistic) alongisde another value of interest (e.g., the p-value for that
statistic). One way to do this is to map the p-value onto the transparency of
the image such that data with "significant" values are highlighted.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found this description a bit mysterious. I'm not clear what is supposed to be "alongside" what. I thought at first you were referring to the x and y axes, but I don't think you are.

I'd simply say that its common to want to indicate significance of data values (or another quantity) using transparency overlain on an image.

@choldgraf
Copy link
Contributor Author

took a stab at addressing comments...LMK what you think!

Copy link
Member

@jklymak jklymak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice!

Copy link
Member

@dstansby dstansby left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this a lot! Couple of things:

  • Can the title cahnge to "Blend transparency with color in 2-D images"? (two 'with's in the same sentence doesn't quite sound right)
  • CircleCI won't let me see why, but the 2.7 doc build is failing for some reason

@choldgraf
Copy link
Contributor Author

The 2.7 fail is mysterious to me... The error message isn't helpful in circle and it builds fine on my 2.7 environment :-/ good idea on the title! Will change when I'm at my computer

@choldgraf
Copy link
Contributor Author

latest push has the new name in it

@choldgraf choldgraf changed the title imshow transparency blend example [MRG] imshow transparency blend example Oct 2, 2017
@choldgraf
Copy link
Contributor Author

@QuLogic do you have any idea what this error could be on Circle 2.7? Not very informative and I can't recreate with 2.7 on my machine...

@dstansby
Copy link
Member

dstansby commented Oct 3, 2017

Lets see if restarting the build does anything

@dstansby
Copy link
Member

dstansby commented Oct 3, 2017

Maybe a sphinx-gallery issue, what version are you building with? CircleCI is sphinx-gallery=0.1.12

@QuLogic
Copy link
Member

QuLogic commented Oct 3, 2017

@choldgraf It looks like something in sphinx-gallery is trying to emit a warning, but doesn't pass the correct number of arguments, so it crashes. Unfortunately, sphinx hides everything but the final exception line, so it's very hard to say where the problem is right now.

@dopplershift
Copy link
Contributor

dopplershift commented Oct 3, 2017

It's a bug in sphinx 1.6.4, caused by fixing a different messaging problem (reported by @anntzer sphinx-doc/sphinx#4070). Forcing installation of sphinx 1.6.3 should fix it.

@choldgraf
Copy link
Contributor Author

so that sounds like a change that should be made to the matplotlib sphinx build, not to this PR yeah? In that case nothing left to change here?

@dstansby
Copy link
Member

dstansby commented Oct 4, 2017

I've added the change here because it's fairly small.

@choldgraf
Copy link
Contributor Author

hmmm, 2.7 still failing. I'll try to debug with sphinx-gallery on my machine

@choldgraf
Copy link
Contributor Author

I'm having a hard time getting the docs to build on my machine (just upgraded to a new computer and things are still wonky). Has anybody else been able to duplicate this sphinx bug? It doesn't seem related to this PR...

@QuLogic
Copy link
Member

QuLogic commented Oct 5, 2017

It looks like some kind of scipy/numpy inconsistency. Maybe something wrong on conda-forge.

@choldgraf
Copy link
Contributor Author

so.....where are we on this one? 2.7 circle or appveyor aren't happy, though unclear if this is related to the PR. can we restart those builds?

@jklymak
Copy link
Member

jklymak commented Oct 12, 2017

2.7 circleci is choking on image_transparency_blend.py so I think that is something you'll have to chase down in a 2.7 environment. Not sure why....

@dstansby
Copy link
Member

It looks to me like there's a problem with scipy.stats finding some numpy methods. Perhaps the easiest fix would be replacing calls to multivariate_normal by something like

z = np.exp(-(x**2 + y**2))
z = z / np.sum(z)

Copy link
Member

@NelleV NelleV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you replace scipy's multivariate_normal by numpy's? Scipy is not a requirements, and only has been added accidentally to our doc-requirements (without the actually documentation being updated).

Also, can you fix the random seed?

@choldgraf choldgraf force-pushed the imshow_trans branch 2 times, most recently from e41171c to bf7567e Compare October 15, 2017 14:52
@choldgraf
Copy link
Contributor Author

latest push removes multivariate_normal (as well as any randomness so I didn't set a seed)

@choldgraf
Copy link
Contributor Author

tests are passing!

Copy link
Member

@NelleV NelleV left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Chris!

@NelleV NelleV merged commit f5ef9e0 into matplotlib:master Oct 15, 2017
@QuLogic QuLogic added this to the v2.2 milestone Oct 15, 2017
@QuLogic QuLogic changed the title [MRG] imshow transparency blend example imshow transparency blend example Oct 15, 2017
@dstansby
Copy link
Member

Should this be backported so it's on the website before 2.2 is released?

@tacaswell tacaswell modified the milestones: v2.2, v2.1.0-doc Oct 15, 2017
@tacaswell
Copy link
Member

@meeseeksdev backport to v2.1.0-doc

@choldgraf
Copy link
Contributor Author

@tacaswell this meeseecks thing is amazing

tacaswell added a commit that referenced this pull request Oct 15, 2017
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.

7 participants