Last active
July 14, 2021 15:17
-
-
Save peterroelants/ccdb07c74abd4de249b4c447dc609ee5 to your computer and use it in GitHub Desktop.
Holoviews Bokeh cmap alpha not working
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "a06c75aa-d805-4e66-b2c7-7d46e8a32e07", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"import numpy as np\n", | |
"\n", | |
"import bokeh\n", | |
"import holoviews as hv\n", | |
"import xarray as xr\n", | |
"import matplotlib.pyplot as plt\n", | |
"import matplotlib\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "18451652-abe3-46de-9acc-90abf8387261", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"_cmap = plt.cm.RdBu\n", | |
"cmap = _cmap(np.arange(_cmap.N))\n", | |
"cmap[:,-1] = np.linspace(0, 1, _cmap.N)\n", | |
"cmap = matplotlib.colors.ListedColormap(cmap)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "33046744-67c7-4812-bf26-34e1c49681f7", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"hv.extension('matplotlib')\n", | |
"\n", | |
"ls = np.linspace(0, 10, 200)\n", | |
"xx, yy = np.meshgrid(ls, ls)\n", | |
"\n", | |
"bounds=(-1,-1,1,1) # Coordinate system: (left, bottom, right, top)\n", | |
"img = hv.Image(np.sin(xx)*np.cos(yy), bounds=bounds).opts(cmap=cmap)\n", | |
"img" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"id": "6a3b6765-2b18-429f-924d-109422d9495f", | |
"metadata": {}, | |
"outputs": [], | |
"source": [ | |
"hv.extension('bokeh')\n", | |
"\n", | |
"ls = np.linspace(0, 10, 200)\n", | |
"xx, yy = np.meshgrid(ls, ls)\n", | |
"\n", | |
"bounds=(-1,-1,1,1) # Coordinate system: (left, bottom, right, top)\n", | |
"img = hv.Image(np.sin(xx)*np.cos(yy), bounds=bounds).opts(cmap=cmap)\n", | |
"img" | |
] | |
} | |
], | |
"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.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 5 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment