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

WIP: Properly set pobj and don't make colorbar if this is None #219

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rjleveque
Copy link
Member

I was seeing strange behavior in GeoClaw plots in Python3, that sometimes the colorbar showed up all green (from the land plots) rather than showing the colorbar for the ocean plot, even though that was the only one requested.

Also when plotting data that was entirely masked on all patches, the gauge was plotted where the colorbar should have been.

I figured out there was a problem in how exec was used that meant pobj wasn't getting set at all. Moreover exec and colorbar both work differently in Python3.

I've rewritten the way pobj is set when calling the pcolor function for this particular plot_type, to put all the arguments into kwargs (rather than constructing a string pcolor_cmd and then using exec).

I suggest we might want to do the same for all other plot_types and I'll work on that unless anyone has a better idea how to do this.

I also modified the code so that if pobj ends up as None, meaning all patches were masked, then it does not make a colorbar. But then the main plot ends up bigger than it would otherwise, unpleasant in an animation with other frames. I think we might want to rewrite all the colorbar stuff to use colorbar.make_axes_gridspec to always make the colorbar axes, and probably we should make it easier for the user to specify other attributes of colorbars (e.g. location, orientation).

@mandli
Copy link
Member

mandli commented Jun 23, 2017

I have been seeing something similar lately as well when playing with some methods for reducing the memory footprint when plotting 1,000s of patches (colorbar and axes are screwed up). I am not sure if these are related but I like the idea of moving towards removing exec commands as much as possible.

@rjleveque
Copy link
Member Author

This is a big enough job that I think we should leave it for the next release, and put a note in that plotting with Python3 may have some problems currently.

@mandli
Copy link
Member

mandli commented Jun 29, 2017

Another way to do this that keeps some of the kwargs separate and maintains the ability to do a particular pc_cmd (for pcolor):

        vmin = pp['pcolor_cmin']
        if vmin is 'auto':
            vmin = None
        vmax = pp['pcolor_cmax']
        if vmax is 'auto':
            vmax = None

        edgecolors = None
        if pp['celledges_show']:
            edgescolors = pp['celledges_color']

        if not var_all_masked:
            plot_cmd = getattr(plt.gca(), pc_cmd)
            pobj = plot_cmd(X_edge, Y_edge, var, cmap=pp['pcolor_cmap'],
                            vmin=vmin, vmax=vmax, edgecolors=edgecolors,
                            **pp['kwargs'])

This was an attempt at fixing the problem in clawpack/geoclaw#275 which did not work.

@mandli
Copy link
Member

mandli commented Jul 2, 2017

I ran into something similar in Python 3 again. I changed assignment of pobj to plotitem._current_pobj so that it gets set by the last non-masked plot object. This could be a quick fix for the rest of the plotitems that are having this issue.

@rjleveque
Copy link
Member Author

Does this also work for making a colorbar when all patches are completely masked? This happens in what we're now testing with using the adjoint to flag for refinement and want to plot the flagged cells. At later times it may happen that no cells are flagged and all patches are masked. I suspect this has to be dealt with differently since it doesn't know the colormap to use in the colorbar if there's no pobj the colorbar goes with.

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.

None yet

2 participants