Plotly Express#
A high-level interface for creating visualizations with Plotly.
Simplifies the process of creating complex visualizations.
import plotly.express as px
Line Plot#
A simple line plot using Plotly Express.
the positional axis order is different from Matplotlib
fig = px.line([1, 2, 3, 4], [1, 4, 2, 3])
fig
Just be explicit, which is always a good idea!
fig = px.line(x=[1, 2, 3, 4], y=[1, 4, 2, 3])
The plotly Figure object offers many methods to update the
Figure
.
There is no
separate axes object. The underlying data can be seen as a dictionary containing
data and the layout to apply (as a json).
dir(fig)
Explore the most common function types intended for users using the first word as the indicator
from collections import Counter
items = Counter([x.split("_")[0] for x in dir(fig) if x.split("_")[0]])
items
Counter({'add': 59,
'update': 18,
'for': 16,
'select': 16,
'to': 6,
'plotly': 3,
'write': 3,
'batch': 2,
'append': 1,
'data': 1,
'frames': 1,
'full': 1,
'get': 1,
'layout': 1,
'pop': 1,
'print': 1,
'set': 1,
'show': 1})
Proteomics data example#
import pathlib
import pandas as pd
dir_data = pathlib.Path("data")
df = pd.read_csv(dir_data / "proteins" / "proteins.csv", index_col=0).T
df
Reference | DMSO_rep1 | DMSO_rep2 | DMSO_rep3 | DMSO_rep4 | Suf_rep1 | Suf_rep2 | Suf_rep3 | Suf_rep4 |
---|---|---|---|---|---|---|---|---|
A5A613 | 27.180209 | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
P00350 | 28.151576 | 27.926204 | 27.653250 | 27.151643 | 27.441837 | 27.031610 | 27.814631 | 27.587217 |
P00363 | 30.247131 | 30.261665 | 29.969625 | 29.470663 | 30.004725 | 30.085997 | 29.904057 | 29.575194 |
P00370 | 27.459171 | 26.873349 | 26.599971 | 26.438623 | 27.399691 | 27.189188 | 27.139030 | 27.223715 |
P00393 | 26.823758 | 26.756617 | 25.442346 | 25.798954 | 26.671118 | 26.885970 | 26.711192 | 26.320866 |
... | ... | ... | ... | ... | ... | ... | ... | ... |
Q57261 | 28.410859 | 27.940694 | 27.070328 | 26.679649 | 27.995432 | 27.055135 | 27.313219 | 26.643479 |
Q59385-2 | 23.554913 | 25.240354 | NaN | 22.524292 | NaN | NaN | NaN | NaN |
Q59385 | 27.640279 | 27.243650 | 27.525020 | 27.403753 | 27.498873 | 27.666957 | 27.708407 | 27.847610 |
Q7DFV3 | 28.512794 | 27.620780 | 27.678892 | 27.255831 | 28.090220 | 27.525537 | 27.814369 | 27.605449 |
Q93K97 | 27.223010 | 25.291110 | 24.358694 | 25.767196 | 25.956190 | 25.230565 | 26.103059 | 26.177716 |
2269 rows × 8 columns
x = df.iloc[:, 0]
px.histogram(x)
px.histogram(df)