Closed donnacalhoun closed 9 years ago
I've added a routine that creates a colorbar for GE, and saves it under
I punted a bit on where put the function (visclaw/geoplot.py?) and where to make the call to call it (setplot.py?) Someone should probably look at the setup. Also, I am ignore any cmin/cmax settings (but using +/-TSUNAMI_MAX_AMPLITUDE, so hopefully it will be correct.
Since it is specific to GeoClaw I think that geoplot.py is a reasonable place to put this. I also think that ignoring the settings for the surface height is fine (and actually should be the way it is plotted) in this case although if I wanted to plot something else like the currents or had a sea-level that was not equal to 0 this would be problematic.
The function that creates the colorbar should probably be called from frametools
however. I just didn't figure out how to get all the pieces that were needed - the colormap being used, the cmin, cmax values, and the plotdir
. This gets back to the question of where this stuff is stored for KML.
Circular issues huh? All of these are stored in the plotdata
object so if you can get in there that might help. Alternatively maybe you can create it when creating the original figure and just refer to that?
I've added a function plotfigure.kml_colorbar
(defined in setplot.py
which gets called in plotpages. In this function, the user sets the cmin/cmax and colormap to use. Ideally this will be consistent with the plotaxes doing the GE plotting.
Alternatively, I could have added more attributes to plotfigure - plotfigure.kml_cmin, plotfigure.kml_cmax, plotfigure.kml_colormap. Either way would work.
Why not just let the user create a color bar in that function or create one by default otherwise?
Good question. But in order to be consistent with what goes into the KML file, the name and location of the
colorbar has to be known when the KML file is created. So I pick the name and then use the
That said, calling this “colorbar” function isn’t very consistent with what else i am doing :
def kml_colorbar(filename):
kml_cmin = -0.2
kml_cmax = 0.2
geoplot.kml_build_colorbar(filename,geoplot.googleearth_transparent,
kml_cmin,kml_cmax)
plotfigure.kml_colorbar = kml_colorbar
To be consistent, I should probably have done something like :
plotfigure.kml_cmin = -0.2
plotfigure.kml_cmax = 0.2
plotfigure.kml_colormap = geoplot.googleearth_transparent
and then I have everything that is needed. I can do it this way, but was starting to feel like I was on borrowed time with all the plotfigure attributes ... (;-))
Donna Calhoun Assistant Professor Department of Mathematics, MG241A Boise State University 1910 University Drive Boise, ID 83725-1555 (208) 426-3386
On Apr 19, 2015, at 4:04 PM, Kyle Mandli notifications@github.com wrote:
Why not just let the user create a color bar in that function or create one by default otherwise?
— Reply to this email directly or view it on GitHub https://github.com/clawpack/visclaw/issues/131#issuecomment-94318602.
Oh, I meant have the user hand you a cbar
object which you then write to the right place which I think will circumvent this problem.
I guess I don't quite follow what you mean.
Have the function by default create a matplotlib.colorbar
object which is then saved as a figure in the right spot. If a user overrides the function they have a lot of control over the colorbar
in that case.
I see. So in kml_build_colorbar
, I could take as an argument 'cbar`, and use that instead of making a separate call (below)
def kml_build_colorbar(cb_filename,cmap,cmin,cmax):
from matplotlib import pyplot
import matplotlib as mpl
fig = pyplot.figure(figsize=(0.8,3))
ax1 = fig.add_axes([0.1, 0.075, 0.25, 0.85])
tick = ax1.yaxis.get_major_ticks()
pyplot.tick_params(axis='y', which='major', labelsize=8)
norm = mpl.colors.Normalize(vmin=cmin,vmax=cmax)
cb1 = mpl.colorbar.ColorbarBase(ax1,cmap=cmap,
norm=norm,
orientation='vertical')
# This is called from plotpages, in <plotdir>.
pyplot.savefig(cb_filename,Transparent=True)
Yeah, this would be the most flexible way to do this I think.
Good idea. I guess I could figure out how to get a colorbar out of the KML plot ... But then a colorbar is attached to an axes, and I want one that has its own axes - I don’t want to use the axes attached to the GE figure.
On Apr 20, 2015, at 5:58 AM, Kyle Mandli notifications@github.com wrote:
Yeah, this would be the most flexible way to do this I think.
— Reply to this email directly or view it on GitHub https://github.com/clawpack/visclaw/issues/131#issuecomment-94433115.
I'd actually like to close this issue too... as far as I can tell, there is no easy way to get the colorbar handle from frametools, without doing what I am already doing in plotpages, i.e. creating a new axes. I agree that it would be better if there was just one colorbar object, regardless of how the plot is created, but it wasn't obvious to me what to do here ...
I'd like to consider closing this too....
I think we can do this in GE...but how?