Changing colorbar label cdsplot.geomap

Hi!

I was wondering if it is possible to change the colorbar label of the cdsplot.geomap plots. It normally takes the variable long name and unit from the data I am plotting, which is sometimes a bit too long for a colorbar label. I can change variable name by changing the attributes with ct.cdm.update_attributes() but I would think it should be possible to change the name in the figure layout.


ct.cdsplot.geomap(data,  title='Historical, '+str(hist_period), pcolormesh_kwargs={'cmap':'Reds','vmin': 0.,'vmax': max_days})


Warm regards,

Joreen

Hi Joreen,

If you want to customize the label of your geomap plot, you need to add the 'label' kwarg as follows:

fig = ct.cdsplot.geomap(

      data,

      title='Historical, '+str(hist_period),

      pcolormesh_kwargs={

          'cmap': 'Reds',

          'vmin':  0.,

          'vmax':  max_days,

          'cbar_kwargs':  {

              'label':  'your_label_name'

         }

     }   

)


As you can see, 'label' must be defined within the 'cbar_kwargs' dictionary.

Here is a working example where you can see how it works. For the sake of clarity, I called the custom name 'your_label_name'. There you need to replace it with the name you want to display on the map.

Hope this will help you.

Best regards,

Monica

That works! Thank you for the help.

Is there documentation where I can find the answer to these types of questions? For example, an overview of which exact arguments to use in the different types of plots. Something like the question I asked is not found in the Toolbox documentation so I was wondering if there is a different place I can look.


Joreen

Hi Joreen,

The plotting functions are hard to document as they have many nested keywords which are documented in the underlying libraries used by the Toolbox (matplotlib and xarray in the present case). So it is best to refer to matplotlib and xarray.plot examples and documentation to discover all the possible keywords which are available.

Your strategy of asking in the forum is very good too as it provides an answer and an example for everyone.

Furthermore Magics is being promoted for the publication of maps with the Toolbox so no guide has been developed about the cdsplot module. 


Regards.

Vivien