-
Notifications
You must be signed in to change notification settings - Fork 29
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
Support for custom colormaps #223
Conversation
This would be a nice addition. Great work! |
Fantastic! I'll give this a test tonight and see if I can write a few tests. Thank you so much for contributing this! |
Codecov ReportAttention: Patch coverage is
❗ Your organization needs to install the Codecov GitHub app to enable full functionality. Additional details and impacted files@@ Coverage Diff @@
## main #223 +/- ##
==========================================
- Coverage 83.93% 83.74% -0.19%
==========================================
Files 26 26
Lines 1021 1046 +25
==========================================
+ Hits 857 876 +19
- Misses 164 170 +6 |
This isn't quite working as expected for colormaps. I'm eager to incorporate this but we'll have to iterate on the serialization of the colormaps to account for different types |
Can you share a couple of examples? I can give it a try |
Sorry for my short comment, I'm unable to take a look immediately, but I was trying to do something like the following: from localtileserver import TileClient, get_leaflet_tile_layer, examples
from matplotlib.colors import ListedColormap, Colormap
from ipyleaflet import Map
tile_client = examples.get_bahamas(debug=True)
cmap1 = ListedColormap(['red','blue'],name='test_1')
cmap2 = ListedColormap(['blue','green'],name='test_2')
cmap3 = ListedColormap(['green','red'],name='test_3')
t = get_leaflet_tile_layer(tile_client, colormap=cmap1)
# t = get_leaflet_tile_layer(tile_client, colormap=[cmap2,cmap1,cmap3])
m = Map(center=tile_client.center(), zoom=tile_client.default_zoom)
m.add_layer(t)
m |
@banesullivan can you explain a bit more what's supposed to happen with t = get_leaflet_tile_layer(tile_client, colormap=[cmap2,cmap1,cmap3]) What about the example with the single colormap? is that one working as expected? |
Sorry for my delay! Let's ignore this actually. this was a supported feature when the underlying tile server used to be large-image where it had some rather unique capabilities for color mapping individual bands. I don't think we need to support that here. |
I've gone ahead and fixed the remaining issues in order to use |
I think its worth noting that in this current implementation, there is a limit to how big these colormaps can be as we embed them in the URL parameters. I recommend just creating named colormaps and registering them with matplotlib in your environment to get around this so that they can be referred to by name, ref: https://matplotlib.org/stable/users/explain/colors/colormap-manipulation.html#registering-a-colormap |
I tested it. Custom colormaps in the format of ListedColormap and list of colors (e.g., ['red', 'green']) work well with leafmap. Registering the custom colormap with matplotlib does not seem to work. Anyway, this is not a big issue. No worries if you don't have time look into it now. https://colab.research.google.com/drive/1JPgl3O-u1ufDEwb3f8fWxiXPqOQyPER7?usp=sharing |
Whoops, I thought this would. I'll try to make sure this gets fixed |
FWIW, I added a failing test case here: opengeos/leafmap#966. No crash or error, but the colors are not as expected. |
This pull request adds support for custom colormaps (resolves #200), either as a matplotlib Colormap, or as a list of colors.
Hopefully I got it right, so far my tests (with
leafmap.add_raster
) seem to work:Here's a test using the example from opengeos/leafmap#673