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

Adapt heatmap layer to be used with a colormap control #1036

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

HaudinFlorence
Copy link
Contributor

@HaudinFlorence HaudinFlorence commented Aug 8, 2022

Adapt heatmap layer for an easier use with a colormap control. The colormap is defined from the color gradient defined in Heatmap class
heatmap
.

@HaudinFlorence HaudinFlorence force-pushed the adapt_Heatmap_layer_to_be_used_with_a_ColormapControl branch from 97a77e7 to 0a396c7 Compare August 8, 2022 18:03
Copy link
Member

@davidbrochart davidbrochart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like you should rebase (79e7d94 is already in master).

Comment on lines 825 to 826
colors = ['blue', 'cyan', 'lime', 'yellow', 'red']
values = [0.4, 0.6, 0.7, 0.8, 1.0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to use traits for these, otherwise they are not configurable.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the review @davidbrochart. Logics of the attributes has been changed a little bit in 93fa3c4, but the choice of the values and colors are configurable using gradient, as shown in the the example notebook Heatmap_with_colormap.

Comment on lines 827 to 833
dict = {}
for i in range(len(values)):
dict[values[i]] = colors[i]
vmin = values[0]
vmax = values[len(values) - 1]
gradient = Dict(dict).tag(sync=True, o=True)
colormap = LinearColormap(colors, vmin=vmin, vmax=vmax)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

vmin, vmax, gradient and colormap should be computed when values or colors change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been tried in commit 93fa3c4.

@HaudinFlorence HaudinFlorence force-pushed the adapt_Heatmap_layer_to_be_used_with_a_ColormapControl branch from 0a396c7 to 93fa3c4 Compare August 9, 2022 15:19
@HaudinFlorence
Copy link
Contributor Author

Looks like you should rebase (79e7d94 is already in master).

This has been fixed.

ipyleaflet/leaflet.py Outdated Show resolved Hide resolved
ipyleaflet/leaflet.py Outdated Show resolved Hide resolved
colors = list(self.gradient.values())
self.vmin = values[0]
self.vmax = values[len(values) - 1]
self.colormap = LinearColormap(colors, vmin=self.vmin, vmax=self.vmax)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the way gradient is defined, is it really a linear color map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this question. There was an argument missing to properly set a piecewise linear colormap as shown on this picture for a gradient set to {0.1 :'orange', 0.2: 'red', 1.0: 'black'}
piecewise_linear_colormap

HaudinFlorence and others added 4 commits August 10, 2022 11:42
Update docstrings

Co-authored-by: David Brochart <david.brochart@gmail.com>
Co-authored-by: David Brochart <david.brochart@gmail.com>
…ar colormap with custom boundary colors and values.
Comment on lines 836 to 837
self.vmin = values[0]
self.vmax = values[-1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we need to sort the gradient by value first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry. I am not sure to understand.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gradient is a dict of "value:color" entries. I don't think we can expect the first entry to have the minimum value and the last entry to have the maximum value.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out. The name values was indeed not a good choice, since it actually refers to the key of the gradient dict. New naming colormap_labels is proposed in 27acdac

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that we need to sort the colormap_labels. What happens to vmin and vmax if gradient = {1.0: 'red', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 0.4: 'blue'}?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I meant that we need to sort the colormap_labels. What happens to vmin and vmax if gradient = {1.0: 'red', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 0.4: 'blue'}?

You're right. Branca colormap requires that the colormaps_labels are sorted. This point has been solved in commit 373f5d9
The example notebook has also been modified for a case where the gradient is initially not sorted.

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