#
# This file is part of Sequana software
#
# Copyright (c) 2016-2021 - Sequana Dev Team (https://sequana.readthedocs.io)
#
# Distributed under the terms of the 3-clause BSD license.
# The full license is in the LICENSE file, distributed with this software.
#
# Website: https://github.com/sequana/sequana
# Documentation: http://sequana.readthedocs.io
# Contributors: https://github.com/sequana/sequana/graphs/contributors
##############################################################################
[docs]class BinaryPercentage:
"""
Expects a dataframe with 2 columns. Their names are used for the labels.
Indices of the dataframe is the sample name.
::
import pandas as pd
from sequana.viz.plotly import BinaryPercentage
hb = BinaryPercentage()
hb.df = pd.DataFrame({"A": [1,50,100], 'B': [1,50,100]})
fig = hb.plot_horizontal_bar(html_code=True)
fig.show()
.. image:: _static/plotly/binary_percentage.png
"""
def __init__(self):
self.df = None
[docs] def plot_horizontal_bar(self, html_code=False, colors=["#389f1f", "#120946"]):
import plotly.graph_objects as go
fig = go.Figure()
Xname = self.df.columns[0]
Yname = self.df.columns[1]
fig.add_trace(go.Bar(y=self.df.index, x=self.df[Yname], name=Yname, marker_color=colors[0], orientation="h"))
fig.add_trace(go.Bar(y=self.df.index, x=self.df[Xname], name=Xname, marker_color=colors[1], orientation="h"))
# Here we modify the tick angle of the xaxis, resulting in rotated labels.
fig.update_layout(barmode="stack", xaxis_tickangle=-45, height=400)
# title="Mapped reads")
if html_code:
return fig
else:
fig.show()