ckoerber / lsqfit-gui

Graphical user interface for performing Bayesian Inference (Bayesian fits).
https://lsqfitgui.readthedocs.io
MIT License
1 stars 0 forks source link

Plot DataFrame convienince method #43

Open ckoerber opened 2 years ago

ckoerber commented 2 years ago

Technically not directly lsqfitgui related, but it would be neat to have a wrapper for plot_gvar taking DataFrames as inputs like px.lines. Maybe, instead of having different rows and columns, also having a select widget for different groups.

ckoerber commented 2 years ago

My first thought was to provide a new px.gv_scatter along the lines of the original scatter

def gv_scatter(...):
    return make_figure(locals(), constructor=GVarScatter)

with a inherited GVarScatter which pre-processes the y to a y mean and y error. Looking at the current go.Scatter, this needs to overload the setter of y.

Since, on __init__(...), y is stored directly in self["y"] (not using the setter), one also needs to adjust the __init__.

class GVarScatter(go.Scatter):

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self.y = self.pop("y")

    @go.Scatter.y.setter
    def y(self, val):
       self["y"] = gv.mean(val)
       self["error_y"] = {"type": "data", "array": gv.sdev(val)}

This works just fine when creating figures. However, it fails for the express version. My prime suspicion is that, at some point, the dict is manipulated and I am not catching it; but I am unsure here.

I suspect a better route would be manipulating the input data frame to avoid messing around with the hidden Plotly infrastructure; and thus reduce the chance that the intended feature needs updating.