YttriLab / A-SOID

An active learning platform for expert-guided, data efficient discovery of behavior.
Other
55 stars 7 forks source link

Adding vectorized graphics to plotly graphs #87

Closed JHartig closed 6 months ago

JHartig commented 7 months ago

Another thing that I came across for figures: Is there an easy way to change the code so the figures that are modifiable via the plotly interface can be exported in vectorized form rather than PNG only? Otherwise it will be difficult to further process anything and that would massively increase the plots' usability beyond initial screening etc. (speaking about actual publication readiness)

Any quickfix that one might change oneself in the code such as you guys suggested for the likelihood ratio? -->

For now, you can change it yourself here:

asoid/utils/load_preprocess.py:332
                    self.llh_value = upload_container.number_input('Likelihood value to filter',
                                                                   min_value=0.05, max_value=0.95,
                                                                   value=0.1)

change to this:

asoid/utils/load_preprocess.py:332
                    self.llh_value = upload_container.number_input('Likelihood value to filter',
                                                                   min_value=0.05, max_value=0.99,
                                                                   value=0.1)

Originally posted by @JensBlack in https://github.com/YttriLab/A-SOID/issues/86#issuecomment-2078976170

JensBlack commented 6 months ago

We are using streamlit to display the interactive plots:

st.plotly_chart

The export format for plots is png by default because we designed this funtionality as a quick screening rather than a publication ready figure. See below how to change that manually.

Alternatively: If you wanted to default view of the figure, you would need to save it manually by adding code to the relevant sections for plotly Plotly documentation.

Here is an example:

asoid/apps/F_predict.py:223

        fig['layout']['yaxis']['autorange'] = "reversed"

       ##This new line saves the plot everytime:
        fig.write_image("images/fig1.svg")

        st.plotly_chart(fig, use_container_width=True, config={
            'toImageButtonOptions': {
                'format': 'png',  # one of png, svg, jpeg, webp <-- This line changes the plots default save
                'filename': f"{str.join('', (vidname, '_', iter_folder, '_bout_durations'))}",
                'height': 720,
                'width': 1280,
                'scale': 3  # Multiply title/legend/axis/canvas sizes by this factor
            }

You could also export it as an html, to retain some of the interactive elements.

If you are interested in our figure ready code, you can find it here (although it might need some adjustment): Asoid_paper

JHartig commented 6 months ago

@JensBlack I changed all to .svg in asoid/apps/F_predict.py:223. That worked! Thanks for that! However, it (obviously) only changes the format for that subfunction.

I would be especially interested to export the UMAP plots from the unsupervised discovery step as well, however the code structuring is different for that part and the "active learning" plots, which are still shown as export as png.

Is there a quick fix to that as well? can't find a similar code structure in C_auto_active_learning and G_unsupervised_discovery to change the plot types.

Thanks and best wishes,

Johannes