barronh / pseudonetcdf

PseudoNetCDF like NetCDF except for many scientific format backends
GNU Lesser General Public License v3.0
76 stars 35 forks source link

Remove colorbar from maps #104

Closed bnmurphy closed 4 years ago

bnmurphy commented 4 years ago

Would be great to be able to pass a kwarg through .plot() to turn off the colorbar on a map.

barronh commented 4 years ago

Started a new feature branch. Need to add documentation and propagate through method overrides. It make take a few days to find the time to complete it. see enhancment/disable-colorbar-map

barronh commented 4 years ago

The update in the branch allows you to provide cbar_kw=False and map_kw=False.

It passes tests on atmos, but is now running tests on Travis Continuous Integration. When it completes, I'll update the main branch.

In the meantime, a quick solution for the colorbar is oddly simple. Basically, you explicitly add an axes for the colorbar. Then you immediately remove it. So you have an axes that is not on the figure. That way the colorbar is made, but not shown. In addition, since it is already removed, the axes available for an active axes -- so you don't have to use plt.sca if your are using a single plot.

Example below:

import PseudoNetCDF as pnc
import matplotlib.pyplot as plt

modpath = '/home/bhenders/TestData/MCIP/METCRO2D_20110101'
modf = pnc.pncopen(modpath, format='ioapi')

cax = plt.axes([.9, .1, .025, .8])
cax.remove()
ax = modf.plot('PBL', cbar_kw=dict(cax=cax))
barronh commented 4 years ago

See PR #105 which has been merged.