Plotter.contours2d() with multidim categorical
Plotter.contours2d()
fails if the plot contains a multidimensional boolean or categorical variable along with another one (no matter what type). It works if the variable is plotted alone.
In this examples, pareal
is a 2-dim DataReal
variable, and pabool
is a 2-dim DataBool
variable.
{
"name": "ValueError",
"message": "The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()",
"stack": "---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Cell In[5], line 1
----> 1 plotter.contours2d(block=\"PA\",attributes=['pareal','pabool'])
File ~\\CODE\\aixd\\src\\aixd\\visualisation\\plotter.py:481, in Plotter.contours2d(self, block, attributes, transformed, downsamp, smoothing, output_name)
476 flag_v = bool(dobj_r.type in [\"categorical\", \"ordinal\"]) + bool(dobj_c.type in [\"categorical\", \"ordinal\"])
477 options = [
478 dobj_r.domain.array if dobj_r.type in [\"categorical\", \"ordinal\"] else None,
479 dobj_c.domain.array if dobj_c.type in [\"categorical\", \"ordinal\"] else None,
480 ]
--> 481 fig = up.contour2d(
482 fig,
483 x=np.asarray(block.data[cols_c])[::downsamp],
484 y=np.asarray(block.data[cols_r])[::downsamp],
485 pos=(ir + 1, ic + 1),
486 flag_v=flag_v,
487 options=options,
488 line={\"smoothing\": smoothing},
489 )
490 else:
491 pass # no plots in the lower triangle
File ~\\CODE\\aixd\\src\\aixd\\visualisation\\utils_plots.py:33, in contour2d(fig, x, y, title, pos, flag_v, options, **kwargs)
31 orientation = \"v\"
32 else:
---> 33 y, x, ind_ordx = reorder_cats(y, x, options[0])
34 orientation = \"h\"
35 return fig.add_trace(
36 go.Violin(
37 x=x.flatten(), y=y.flatten(), fillcolor=\"lightblue\", points=False, showlegend=False, line={\"width\": 0.5, \"color\": \"black\"}, orientation=orientation, **kwargs
(...)
40 col=pos[1],
41 )
File ~\\CODE\\aixd\\src\\aixd\\visualisation\\utils_plots.py:79, in reorder_cats(x, counts, options)
77 def reorder_cats(x: List, counts: List, options: List) -> Tuple[List, List, List]:
78 if options is not None:
---> 79 ind_ord = np.concatenate([np.argwhere(x.flatten() == o) for o in options if o in list(x)]).flatten()
80 x, counts = x[ind_ord], counts[ind_ord]
81 else:
File ~\\CODE\\aixd\\src\\aixd\\visualisation\\utils_plots.py:79, in <listcomp>(.0)
77 def reorder_cats(x: List, counts: List, options: List) -> Tuple[List, List, List]:
78 if options is not None:
---> 79 ind_ord = np.concatenate([np.argwhere(x.flatten() == o) for o in options if o in list(x)]).flatten()
80 x, counts = x[ind_ord], counts[ind_ord]
81 else:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()"
}
Edited by Alessandro Maissen