Skip to content

Commit

Permalink
improvement in colobar label of pyart/graph/gridmapdisplay.py
Browse files Browse the repository at this point in the history
  • Loading branch information
jfigui committed May 25, 2023
1 parent 7762800 commit b46a451
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions pyart/graph/gridmapdisplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,12 +1225,9 @@ def plot_colorbar(self, mappable=None, orientation='horizontal',
if label is None:
if len(self.fields) == 0:
raise ValueError('field must be specified.')

field = self.grid.fields[self.fields[-1]]
if 'long_name' in field and 'units' in field:
label = field['long_name'] + '(' + field['units'] + ')'
else:
label = ''
if field is None:
field = self.fields[-1]
label = self._get_colorbar_label(field)

# plot the colorbar and set the label.
cb = fig.colorbar(mappable, orientation=orientation, ax=ax, cax=cax)
Expand Down Expand Up @@ -1416,6 +1413,22 @@ def cartopy_coastlines(self):
category='physical', name='coastline', scale='10m',
facecolor='none')

def _get_colorbar_label(self, field):
""" Return a colorbar label for a given field. """
last_field_dict = self.grid.fields[field]
if 'standard_name' in last_field_dict:
standard_name = last_field_dict['standard_name']
elif 'long_name' in last_field_dict:
standard_name = last_field_dict['long_name']
else:
standard_name = field

if 'units' in last_field_dict:
units = last_field_dict['units']
else:
units = '?'
return common.generate_colorbar_label(standard_name, units)


def lambert_xticks(ax, ticks):
""" Draw ticks on the bottom x-axis of a Lambert Conformal projection. """
Expand Down

0 comments on commit b46a451

Please sign in to comment.