Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow colorbar ticks at arbitrary position #113

Merged
merged 1 commit into from
Nov 4, 2022

Conversation

kota7
Copy link
Contributor

@kota7 kota7 commented Aug 15, 2022

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: python-visualization/folium#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

Screenshot_2022-08-16_01-44-14

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

Screenshot_2022-08-16_01-43-55

@Conengmo Conengmo merged commit 1f42a66 into python-visualization:master Nov 4, 2022
@Conengmo
Copy link
Member

Conengmo commented Nov 4, 2022

Perfect! Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants