Skip to content
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

Add ability to pass norm and alpha values to imshow #297

Merged
merged 2 commits into from
Jan 24, 2024

Conversation

kbarnhart
Copy link
Contributor

I've found it useful to be able to specify a norm object to plotitem for 2d_imshow

e.g.,

plotitem.imshow_norm = mpl.colors.LogNorm(0.001, 10, clip=True)

Similarly, I've found it useful to provide an alpha value to make an imshow transparent (e.g., on top of a hillshade).

This PR adds these two features (I'll make an associated PR for the docs shortly).

@kbarnhart
Copy link
Contributor Author

This is not quite ready to be considered because the norm is not being correctly reflected in the colorbar. Will note here when it is ready for further consideration.

@mandli mandli changed the title Add ability to pass norm and alpha values to imshow WIP: Add ability to pass norm and alpha values to imshow Nov 14, 2023
@mandli
Copy link
Member

mandli commented Nov 14, 2023

There are some tools to do this but I am not sure that they match what you would like. The norms are always more difficult to work with so it also may be something we would put into an example or FAQ if the implementation is too difficult.

@kbarnhart
Copy link
Contributor Author

thanks @mandli - If I get it to work I will make an example. I got it to work before... so 🤞 I can get it to work again.

point me towards the tools? If they are sufficient, I'd happily migrate.

@rjleveque
Copy link
Member

@kbarnhart: It seems like adding it as you do here should work, and would be a good addition. I'm not sure offhand why it's not reflected in the colorbar.

In looking at the code I see that we allow setting plotitem.kwargs for pcolor plots and these are appended to the plot command, but not for imshow. I'm not sure why not, but that might also be nice to allow for users who want to pass in other arguments we don't explicitly support.

@kbarnhart kbarnhart changed the title WIP: Add ability to pass norm and alpha values to imshow Add ability to pass norm and alpha values to imshow Jan 9, 2024
@kbarnhart
Copy link
Contributor Author

After a bit of digging, I concluded that the reason I thought it was not working was because no colorbar ticks were being draw (thus it was not possible to evaluate if the colorbar norm was working as expected). The following example works as expected for the chile2010 case:

    from matplotlib.colors import SymLogNorm
    #.... many missing lines
    plotitem = plotaxes.new_plotitem(plot_type='2d_imshow')
    plotitem.plot_var = geoplot.surface_or_depth
    plotitem.imshow_cmap = geoplot.tsunami_colormap
    plotitem.imshow_norm = SymLogNorm(vmin=-2, vmax=2, linthresh=0.02)
    plotitem.imshow_alpha=1.0
    plotitem.add_colorbar = True
    plotitem.colorbar_ticks = [-2, -.2, -0.02,0,0.02, 0.2, 2]
    plotitem.colorbar_tick_labels = [-2, -.2, -0.02,0,0.02, 0.2, 2]
    plotitem.amr_celledges_show = [0,0,0]
    plotitem.patchedges_show = 1

@rjleveque and I just discussed whether additional kwargs might ever need to be passed to imshow (besides the two I've just added) and concluded that no other kwargs would make sense to pass. Therefore, I've not added additional kwargs.

I think that this pr and clawpack/doc#227 are ready to be considered.

@rjleveque rjleveque merged commit 47f7d93 into clawpack:master Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants