NOAA-PMEL/PyFerret

After a plot using both /SET and /PALETTE, next plot doesn't revert to default palette.

Closed this issue · 1 comments

This is not a new bug. In what is probably a rare combination of commands, if a plot uses /PALETTE to change color palettes, and also the /SET command to make custom settings with pplus commands, then the next color plot does not revert to the default color palette as it should, but keeps the palette setting from the previous plot command

Example

! Define an example 2D variable to plot
let var = i[i=1:5] + j[j=1:5]

! Here is the correct behavior:
! After a /palette setting on one plot, the next one uses the default palette.

set view ul
shade/palette=purple_red/title="1) shade/palette=purple_red var"  var   

set view ur
shade/title="2) Without /palette. Reverts to default palette"  var  


! Now, the incorrect behavior where /PALETTE= /SET results in
! the wrong palette being used on the subsequent plot. 

set view ll
shade/set/palette=green_brown /title="3) shade/set/palette=green_brown" var  
   ppl shakey,1,1,,0,-2   ! Set the # digits used in colorbar labels
ppl shade

set view lr
shade/title="4) 

palette_bug

This is fixed, in the routines
fer/common/xplot_state.cmn fer/plt/disp_data_set_up.F fer/plt/disp_reset.F fer/xeq/xeq_pplus.F

and checked in on my fork ACManke/PyFerret

When plot commands are issued without /SET, there are calls after the plot has been drawn to restore settings that may have been changed - so in xeq_shade.F for instance, a bunch of calls are made to set things up, then there's a comment "shade it", followed by calls to PPLCMD which goes into the pplus world and makes the plot. On returning from PPLCMD, there are calls to clear the opacity settings, restore the original color spectrum, restore the color key style, etc. IF a color-palette setting was made, a flag "spectrum" was set, so xeq_shade does this after the call to PPLCMD:

       IF ( spectrum ) CALL PPL_SHASET( 'SPECTRUM' )

If it was a SHADE/SET, then the routine xeq_shade exits before the PPLCMD calls. The next commands from the Ferret script or command line, are then some set of PPL custom commands, followed by PPL SHADE. The PPL commands execute xeq_pplus.F, which make individual pplus calls. Or, if the command is a Ferret-plot-call such as PPL SHADE, PPL CONTOUR, etc, then it knows it's finishing off a SHADE/SET or whatever it is, and it does some things to restore the plot state. Restoring the color-palette setting had not been part of these calls.

So, we need to restore the color palette to what the current default palette is, with a call from xeq_pplus to PPL_SHASET( 'SPECTRUM' ). HOWEVER, if the SHADE/SET did not have a /PALETTE= command change color palettes, we don't want to do this. The user may have changed color palettes for the session to some other color palette, and if we just always do the PPL_SHASET after a SHADE/SET, that PPL_SHASET will wipe out their custom color palette.

This means setting up a flag which is set for the case of SHADE/PALETTE=/SET or FILL/PALETTE=/SET and so on, and only in that instance doing the PPL_SHASET when xeq_pplus.F is called to finish off the plot.