taborlab / FlowCal

Python Flow Cytometry Calibration Library
MIT License
48 stars 23 forks source link

Violin plots fail with list inputs when data scale is logicle. #351

Open JS3xton opened 3 years ago

JS3xton commented 3 years ago

Violin plots fail with list inputs when data scale is logicle in FlowCal v1.3.0.

E.g.,

>>> FlowCal.plot.violin(data=[1,3,2,4,3])

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\sexto\Downloads\taborlab_FlowCal\FlowCal\plot.py", line 1810, in violin
    t = _LogicleTransform(data=data, channel=channel)
  File "C:\Users\sexto\Downloads\taborlab_FlowCal\FlowCal\plot.py", line 271, in __init__
    if d.ndim > 1:
AttributeError: 'list' object has no attribute 'ndim'

This happens because plot._LogicleTransform checks for multidimensional data using the ndim attribute, which numpy arrays have but lists do not. (The plot violin functions use _LogicleTransform to calculate default bin edges and implicitly when they set the Logicle scale. In both cases, data are provided as is.)

A simple work-around is to pass a numpy array to the plot functions.