enveda / mspaint

multi-engine painting of mass spec data
GNU General Public License v2.0
0 stars 0 forks source link

nicer mirror plots #2

Open chanana opened 1 year ago

chanana commented 1 year ago
    def _make_mirror_plot_plotly(
        self,
        mzs_on_bottom: np.array,
        intensities_on_bottom: np.array,
        mzs_on_top: np.array,
        intensities_on_top: np.array,
        xaxis_range: Tuple[int, int],
        label_top: str = "top",
        label_bottom: str = "bottom",
        title: str = "title",
    ):
        fig = go.Figure()  # init figure

        fig.add_trace(
            go.Scatter(
                x=mzs_on_bottom,  # an array
                y=intensities_on_bottom,  # an array of same size
                name=label_bottom,
                mode="lines",
                #             customdata=intensities_ref,
                hovertemplate="intensity:%{y}<br>m/z:%{x}<br>type:bottom",
            )
        )

        # plot on top
        fig.add_trace(
            go.Scatter(
                x=mzs_on_top,
                y=intensities_on_top,
                name=label_top,
                mode="lines",
                hovertemplate="Intensity: %{y}<br>m/z:%{x}<br>type:top",
            )
        )
        fig.update_layout(
            hovermode="x unified"
        )  # allows you to look at both traces at once
        fig.update_layout(
            xaxis_range=xaxis_range,
            title=title,
            xaxis_title="m/z",
            yaxis_title="Intensity",
            #     height=400, # size of plot
            #     width=700, # size of plot
            legend_orientation="h",
            legend_x=-0.05,
            legend_y=1.1,
        )
        return fig