-
Notifications
You must be signed in to change notification settings - Fork 363
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
HaudinFlorence
wants to merge
13
commits into
jupyter-widgets:master
Choose a base branch
from
HaudinFlorence:adapt_Heatmap_layer_to_be_used_with_a_ColormapControl
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
9c2efed
Adapt Heatmap layer for an easier use with a ColormapControl.
HaudinFlorence e8bbcc0
Fix flake8 formatting issue.
HaudinFlorence 93fa3c4
Simplify the logics of attributes of Heatmap class and compute vmin, …
HaudinFlorence 92ff447
Update docstrings and change self.values/self.colors into values/colo…
HaudinFlorence 8675531
Update obsolete argument in @observe decorator.
HaudinFlorence b3d0cd5
Update ipyleaflet/leaflet.py
HaudinFlorence 0e186d1
Update ipyleaflet/leaflet.py
HaudinFlorence 6f8773e
Update obsolete argument in @observe decorator.
HaudinFlorence e1674ce
Add index argument in LinearColormap to properly set a piecewise line…
HaudinFlorence 27acdac
Change values to colormap_labels in _get_data method .
HaudinFlorence 373f5d9
Sort the gradient to be compatible with the colormap treating with or…
HaudinFlorence ec2e2a8
Update ipyleaflet/leaflet.py
HaudinFlorence f6f10a5
Remove comment and unsorted gradient and fix flake8 issue.
HaudinFlorence File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "98958552-db61-4b15-9025-8483234118b3", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# Set up for JupyterLite\n", | ||
"try:\n", | ||
" import piplite\n", | ||
" await piplite.install('ipyleaflet')\n", | ||
"except ImportError:\n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "974bc9b2-4a25-455b-8c4d-ca565e21f146", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import ipyleaflet\n", | ||
"from random import uniform\n", | ||
"import time\n", | ||
"from branca.colormap import linear, LinearColormap" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "fa27e0da-7047-4f06-93e8-3fb230e554d4", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"def create_random_data(length):\n", | ||
" \"Return a list of some random lat/lon/value triples.\"\n", | ||
" return [\n", | ||
" [uniform(-80, 80), uniform(-180, 180), uniform(0, 1000)] for i in range(length)\n", | ||
" ]" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"id": "cd1fc9dd-addf-4085-95ff-b8d4b983491f", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"m = ipyleaflet.Map(center=[0, 0], zoom=2)\n", | ||
"heat = ipyleaflet.Heatmap(locations=create_random_data(1000), radius=20, blur=10, gradient={0.1 : 'orange', 0.2 : 'red', 1.0 :'black'})\n", | ||
"colormap_control = ipyleaflet.ColormapControl(\n", | ||
" caption='Intensity',\n", | ||
" colormap=heat.colormap,\n", | ||
" value_min=heat.vmin,\n", | ||
" value_max=heat.vmax,\n", | ||
" position='topright',\n", | ||
" transparent_bg=True,\n", | ||
" )\n", | ||
"m.add(heat)\n", | ||
"m.add(colormap_control)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3 (ipykernel)", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.13" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 5 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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 thegradient
dict. New namingcolormap_labels
is proposed in 27acdacThere was a problem hiding this comment.
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 tovmin
andvmax
ifgradient = {1.0: 'red', 0.6: 'cyan', 0.7: 'lime', 0.8: 'yellow', 0.4: 'blue'}
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. Branca colormap requires that the
colormaps_labels
are sorted. This point has been solved in commit 373f5d9The example notebook has also been modified for a case where the gradient is initially not sorted.