add_colorbar
- Maps.add_colorbar(m, pos=0.4, inherit_position=None, margin=None, hist_size=0.8, hist_bins=256, extend_frac=0.025, orientation='horizontal', dynamic_shade_indicator=False, show_outline=False, tick_precision=2, tick_formatter=None, log=False, out_of_range_vals='clip', hist_kwargs=None, **kwargs)
Add a colorbar to the map.
The colorbar always represents the data of the associated Maps-object that was assigned in the last call to m.plot_map().
By default, the colorbar will only be visible on the layer of the associated Maps-object.
After the colorbar has been created, it can be accessed via:
>>> cb = m.colorbar
- Parameters
pos (float or 4-tuple, optional) –
float: fraction of the axis size that is used to create the colorbar. The axes of the Maps-object will be shrinked accordingly to make space for the colorbar.
4-tuple (x0, y0, width, height): Absolute position at which the colorbar should be placed in units. In this case, existing axes are NOT automatically re-positioned!
Note: By default, multiple colorbars on different layers share their position! To force placement of a colorbar, use “inherit_position=False”.
The default is 0.4.
inherit_position (bool or None optional) –
Indicator if the colorbar should share its position with other colorbars that represent datasets on the same plot-axis.
If True, and there is already another colorbar for the given plot-axis, the value of “pos” will be ignored and the new colorbar will share its position with the parent-colorbar. (e.g. all colorbars for a given axis will overlap and moving a colorbar in one layer will move all other relevant colorbars accordingly).
If None: If the colorbar is added on a different layer than the parent colorbar, use “inherit_position=True”, else use “inherit_position=False”.
The default is None
hist_size (float or None) –
The fraction of the colorbar occupied by the histogram.
None: no histogram will be drawn
0:
0.9: 90% histogram, 10% colorbar
1: only histogram
hist_bins (int, list, tuple, array or "bins", optional) –
If int: The number of histogram-bins to use for the colorbar.
If list, tuple or numpy-array: the bins to use
If “bins”: use the bins obtained from the classification (ONLY possible if a classification scheme is used!)
The default is 256.
extend_frac (float, optional) – The fraction of the colorbar-size to use for extension-arrows. (Extension-arrows are added if out-of-range values are found!) The default is 0.025.
orientation (str, optional) – The orientation of the colorbar (“horizontal” or “vertical”). The default is “horizontal”.
dynamic_shade_indicator (bool, optional) –
ONLY relevant if data-shading is used! (“shade_raster” or “shade_points”)
False: The colorbar represents the actual (full) dataset
True: The colorbar is dynamically updated and represents the density of the shaded pixel values within the current field of view.
The default is False.
show_outline (bool or dict) –
Indicator if an outline should be added to the histogram. (e.g. a line encompassing the histogram) If a dict is provided, it is passed to plt.step() to style the line. (e.g. with ordinary matplotlib parameters such as color, lw, ls etc.) If True, the following properties are used:
{“color”: “k”, “lw”: 1}
The default is False.
tick_precision (int or None) – The precision of the tick-labels in the colorbar. (e.g. a precision of 2 means that 0.12345 will be shown as 0.12) The default is 2.
tick_formatter (callable) –
A function that will be used to format the ticks of the colorbar. The function will be used with matpltlibs set_major_formatter… For details, see: https://matplotlib.org/stable/api/_as_gen/matplotlib.axis.Axis.set_major_formatter.html
Call-signagure:
>>> def tick_formatter(x, pos): >>> # x ... the tick-value >>> # pos ... the tick-position >>> return f"{x} m"
The default is None.
log (bool, optional) – Indicator if the y-axis of the plot should be logarithmic or not. The default is False
out_of_range_vals (str or None) –
if “mask”: out-of range values will be masked. (e.g. values outside the colorbar limits are not represented in the histogram and NO extend-arrows are added)
if “clip”: out-of-range values will be clipped. (e.g. values outside the colorbar limits will be represented in the min/max bins of the histogram)
The default is “clip”
hist_kwargs (dict) – A dictionary with keyword-arguments passed to the creation of the histogram (e.g. passed to plt.hist() )
kwargs – All additional kwargs are passed to the creation of the colorbar (e.g. plt.colorbar())
See also
-
Examples
>>> x = y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> data = [1, 2, 6, 6, 6, 8, 7, 3, 9, 10] >>> m = Maps() >>> m.set_data(data, x, y) >>> m.plot_map() >>> m.add_colorbar(label="some data")
>>> x = y = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] >>> data = [1, 2, 6, 6, 6, 8, 7, 3, 9, 10] >>> m = Maps() >>> m.set_data(data, x, y) >>> m.set_classify.Quantiles(k=6) >>> m.plot_map() >>> m.add_colorbar(hist_bins="bins", label="some data")