taborlab / FlowCal

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

Violin plots fail with Logicle scale if no channel is specified. #341

Closed JS3xton closed 3 years ago

JS3xton commented 3 years ago

The following code fails using commit bc98686677dde12dd6ba6987b8d753fdb7692c5c (a few commits upstream of when plot-violin was merged into develop):

>>> import numpy as np

>>> data = np.random.lognormal(size=100)
>>> FlowCal.plot.violin(data=data)  # default `yscale` is 'logicle'

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\sexto\.conda\envs\py3_anaconda2020.07_fc_JS3xton_bc98686\lib\site-packages\flowcal-1.2.2-py3.8.egg\FlowCal\plot.py", line 1766, in violin
  File "C:\Users\sexto\.conda\envs\py3_anaconda2020.07_fc_JS3xton_bc98686\lib\site-packages\flowcal-1.2.2-py3.8.egg\FlowCal\plot.py", line 259, in __init__
ValueError: if data is provided, a channel should be specified

The error comes from plot._LogicleTransform, which requires channel if data is specified.

The violin plot functions implicitly use _LogicleTransform when they set the Logicle scale, and they don't check whether channel is None:

    if xscale == 'logicle':
        plt.xscale(xscale, data=data, channel=channel)
    else:
        plt.xscale(xscale)
    if yscale == 'logicle':
        plt.yscale(yscale, data=data, channel=channel)
    else:
        plt.yscale(yscale)
JS3xton commented 3 years ago

Fixed in FlowCal v1.3.0.