holoviz / holoviews

With Holoviews, your data visualizes itself.
https://holoviews.org
BSD 3-Clause "New" or "Revised" License
2.7k stars 404 forks source link

Irregular behaviour when plotting with categorical axes #3111

Closed mgorfer closed 1 year ago

mgorfer commented 6 years ago

I import a DataArray from xarray and create a hv.Dataset :Dataset [x,y] (z). The dimension x is a categorical axis and y is a default linear axis. Depending on the hv.element I am using this is either working as expected (for hv.Scatter, hv.Curve, hv.Bar), or I get the error TypeError: unsupported operand type(s) for -: 'str' and 'str' (for hv.QuadMesh, hv.Image, hv.HeatMap).

To get the result I want in a hv.QuadMesh, first in xarray I change the categorical x-axis to a linear axis x =[0,1,2]. Then I set the xticks in the plot options and I can create the plot I want to.

%%opts QuadMesh [xticks=[(0, "xtick_0"), (1, "xtick_1"),(2, "xtick_2")]]
hv_ds.to(hv.QuadMesh, ['x', 'y'])

I am perfectly fine with my xticks to appear evenly spaced on the x-axis, like in my example below, and I guess this should be the standard behaviour for any categorical axis. Is this detour I was taking intended or is this an issue? custom_xticks

philippjfr commented 6 years ago

It should probably be documented somewhere but hv.Image and hv.QuadMesh are defined as a binned 2D continuous space so using them for categorical values does not make sense. At minimum that should raise a better error. A HeatMap on the other hand is defined as a purely categorical element. Currently there is no mixed heatmap/raster like element that supports one continuous and one categorical axis, however we have plans for Raster to support this.

github-actions[bot] commented 3 weeks ago

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.