This extend the ColorMap and its successors LinearColormap and StepColormap so that one may specify the positions of ticks to display independently of the index parameter. Currently the index parameter is used both to determine the color scale and as the location of the legend labels.
It is possible that the two roles are better to be separated. For example, one decided to split colors by the percentile values of the data, which would result in any numeric values. However, for the visualization purpose, numbers shown in the color bar are better to be "good" numbers such as 0, 50, 100. For example, this discussion is related to this feature: https://github.com/python-visualization/folium/issues/1374.
This PR enables this feature by an adding additional argument tick_labels to LinearColormap and StepColormap, which is used as the tick positions. The default value is None, for which the current behavior is maintained. This logic is implemented in the ColorMap.render method.
In addition the LinearColormap.to_step method is updated so that the tick_labels attribute is maintained to the result.
Examples:
import folium
from branca.colormap import LinearColormap
colormap = LinearColormap(["blue", "yellow", "red"], index=[1, 10, 100], vmin=1, vmax=100,
tick_labels=[30, 80, 150])
m = folium.Map(location=[48, -102], zoom_start=3)
colormap.add_to(m)
m
import folium
from branca.colormap import StepColormap
colormap = StepColormap(["blue", "yellow", "red"], index=[1, 10, 100], vmin=1, vmax=100,
tick_labels=[30, 80, 150])
m = folium.Map(location=[48, -102], zoom_start=3)
colormap.add_to(m)
m
This extend the
ColorMap
and its successorsLinearColormap
andStepColormap
so that one may specify the positions of ticks to display independently of theindex
parameter. Currently theindex
parameter is used both to determine the color scale and as the location of the legend labels. It is possible that the two roles are better to be separated. For example, one decided to split colors by the percentile values of the data, which would result in any numeric values. However, for the visualization purpose, numbers shown in the color bar are better to be "good" numbers such as 0, 50, 100. For example, this discussion is related to this feature: https://github.com/python-visualization/folium/issues/1374.This PR enables this feature by an adding additional argument
tick_labels
toLinearColormap
andStepColormap
, which is used as the tick positions. The default value isNone
, for which the current behavior is maintained. This logic is implemented in theColorMap.render
method.In addition the
LinearColormap.to_step
method is updated so that thetick_labels
attribute is maintained to the result.Examples: