You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description of expected behavior and the observed behavior
I'm plotting a 2d field using hvplot.image (same with hvplot.quadmesh) using a colormap from cmocean (same with any matplotlib.colors.Colormap object, including matplotlib.colormaps ones).
I expect it to just do the plot using the provided colormap, but instead I get the following error: TypeError: argument of type 'LinearSegmentedColormap' is not iterable.
I believe it is because the argument passed through cmap is at some point assumed to be a string (not the case here). Adding the dummy argument color="black" and it works as expected (because a test evaluates to False in the implementation).
Complete, minimal, self-contained example code that reproduces the issue
# using cmoceanimportcmocean.cmascmoimporthvplot.xarray# noqaimportxarrayasxrds=xr.tutorial.open_dataset("air_temperature")
da=ds.air.isel(time=0)
plot=da.hvplot.image(cmap=cmo.thermal) # this works: plot = da.hvplot.image(cmap=cmo.thermal, color="black")
# using matplotlibimporthvplot.xarray# noqafrommatplotlibimportcolormapsimportxarrayasxrds=xr.tutorial.open_dataset("air_temperature")
da=ds.air.isel(time=0)
plot=da.hvplot.image(cmap=colormaps["viridis"]) # this works: plot = da.hvplot.image(cmap=colormaps["viridis"] color="black")
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[5], [line 9](vscode-notebook-cell:?execution_count=5&line=9)
[6](vscode-notebook-cell:?execution_count=5&line=6) ds = xr.tutorial.open_dataset("air_temperature")
[7](vscode-notebook-cell:?execution_count=5&line=7) da = ds.air.isel(time=0)
----> [9](vscode-notebook-cell:?execution_count=5&line=9) plot = da.hvplot.image(cmap=cmo.thermal)
File ~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2155, in hvPlot.image(self, x, y, z, colorbar, **kwds)
[2103](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2103) def image(self, x=None, y=None, z=None, colorbar=True, **kwds):
[2104](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2104) """
[2105](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2105) Image plot
[2106](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2106)
(...)
[2153](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2153) - Plotly: https://plotly.com/python/imshow/
[2154](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2154) """
-> [2155](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:2155) return self(x, y, z=z, kind='image', colorbar=colorbar, **kwds)
File ~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:95, in hvPlotBase.__call__(self, x, y, kind, **kwds)
[92](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:92) plot = self._get_converter(x, y, kind, **kwds)(kind, x, y)
[93](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:93) return pn.panel(plot, **panel_dict)
---> [95](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:95) return self._get_converter(x, y, kind, **kwds)(kind, x, y)
File ~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:102, in hvPlotBase._get_converter(self, x, y, kind, **kwds)
[100](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:100) y = y or params.pop('y', None)
[101](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:101) kind = kind or params.pop('kind', None)
--> [102](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/plotting/core.py:102) return HoloViewsConverter(self._data, x, y, kind=kind, **params)
File ~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:796, in HoloViewsConverter.__init__(self, data, x, y, kind, by, use_index, group_label, value_label, backlog, persist, use_dask, crs, fields, groupby, dynamic, grid, legend, rot, title, xlim, ylim, clim, robust, symmetric, logx, logy, loglog, hover, hover_cols, hover_formatters, hover_tooltips, subplots, label, invert, stacked, colorbar, cticks, datashade, rasterize, downsample, resample_when, row, col, debug, framewise, aggregator, projection, global_extent, geo, precompute, flip_xaxis, flip_yaxis, dynspread, x_sampling, y_sampling, pixel_ratio, project, tools, attr_labels, coastline, tiles, tiles_opts, sort_date, check_symmetric_max, transforms, stream, cnorm, features, rescale_discrete_levels, autorange, subcoordinate_y, **kwds)
[793](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:793) if plotwd in kwds:
[794](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:794) plot_opts[plotwd] = kwds.pop(plotwd)
--> [796](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:796) self._style_opts, plot_opts, kwds = self._process_style(kwds, plot_opts)
[798](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:798) for axis_name in ['xaxis', 'yaxis']:
[799](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:799) if axis_name in kwds:
File ~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1488, in HoloViewsConverter._process_style(self, kwds, plot_opts)
[1486](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1486) color = style_opts['color']
[1487](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1487) elif not isinstance(cmap, dict):
-> [1488](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1488) if cmap and any(c in cmap for c in categories):
[1489](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1489) color = process_cmap(cmap or self._default_cmaps['categorical'], categorical=True)
[1490](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1490) else:
File ~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1488, in <genexpr>(.0)
[1486](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1486) color = style_opts['color']
[1487](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1487) elif not isinstance(cmap, dict):
-> [1488](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1488) if cmap and any(c in cmap for c in categories):
[1489](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1489) color = process_cmap(cmap or self._default_cmaps['categorical'], categorical=True)
[1490](https://file+.vscode-resource.vscode-cdn.net/Users/bertrava/projects/vb-phd/notebooks/daily/~/miniconda3/envs/vb-phd/lib/python3.11/site-packages/hvplot/converter.py:1490) else:
TypeError: argument of type 'LinearSegmentedColormap' is not iterable
I may be interested in making a pull request to address this
The text was updated successfully, but these errors were encountered:
vadmbertr
changed the title
Use of colormap objects result in TypeError: argument of type 'LinearSegmentedColormap' is not iterable
Use of matplotlib.colors.Colormap as cmap arguments objects result in TypeError: argument of type 'LinearSegmentedColormap' is not iterableDec 3, 2024
vadmbertr
changed the title
Use of matplotlib.colors.Colormap as cmap arguments objects result in TypeError: argument of type 'LinearSegmentedColormap' is not iterable
Use of matplotlib.colors.Colormap objects as cmap argument results in TypeError: argument of type 'LinearSegmentedColormap' is not iterableDec 3, 2024
Hi,
ALL software version info
(this library, plus any other relevant software, e.g. bokeh, python, notebook, OS, browser, etc should be added within the dropdown below.)
Software Version Info
Description of expected behavior and the observed behavior
I'm plotting a 2d field using
hvplot.image
(same withhvplot.quadmesh
) using a colormap fromcmocean
(same with anymatplotlib.colors.Colormap
object, includingmatplotlib.colormaps
ones).I expect it to just do the plot using the provided colormap, but instead I get the following error:
TypeError: argument of type 'LinearSegmentedColormap' is not iterable
.I believe it is because the argument passed through
cmap
is at some point assumed to be astring
(not the case here). Adding the dummy argumentcolor="black"
and it works as expected (because a test evaluates toFalse
in the implementation).Complete, minimal, self-contained example code that reproduces the issue
Stack traceback and/or browser JavaScript console output
The text was updated successfully, but these errors were encountered: