Note
Go to the end to download the full example code.
Frequency Plots¶
Frequency plots/charts refer to stacked horizontal bar charts which show frequency distribution of data across labelled and segmented subgroups, with segment widths representing the proportion or frequency of the subgroup. These can be generated using the fig_frequency_chart() function, which returns a Plotly Go Figure object.
The plot below was generated using a synthetic dataset of patient treatment complications for Dengue, consisting of ten patients and five complications.
The dataset is given below as a table (but can also be loaded from the docs/sources/plot-gallery/examples/csv/frequency.csv file).
Subgroup Label / Outcome Variable |
Description / Short Label |
Frequency |
|---|---|---|
Dengue Haemorrhagic Fever |
DHF |
0.4 |
Dengue Shock Syndrome |
DSS |
0.2 |
Thrombocytopenia |
Low Platelets |
0.6 |
Hepatomegaly |
Hepatomegaly |
0.3 |
Plasma Leakage |
Plasma Leakage |
0.1 |
The fig_frequency_chart() function expects a dataframe with the following columns (in no particular order):
"label"- the subgroup label / outcome variable column of the table"short_label"- the description column of the table"proportion"- the frequency column of the table
Here are the Python steps you need to generate the plot using the fig_frequency_chart() function:
43 import pandas as pd
44 from isaricanalytics.visualisation import fig_frequency_chart
45
46 # Load the CSV
47 data = pd.read_csv("./csv/frequency.csv")
48
49 # Create and display the figure
50 fig = fig_frequency_chart(
51 data,
52 title="Frequency Chart of Synthetic Dengue Patient Complications",
53 )
54 fig.update_layout(autosize=True)
55 fig
Note
Any dataframe or CSV column names, or dictionary field labels, in the example above that are not specific to the dataset must be as given, otherwise the function may throw an exception or return an incorrect figure.
The figure height and width parameters can be set using the height
and width parameters, but it may be more convenient to let Plotly handle
this using the figure layout autosize
parameter. Refer to the fig_frequency_chart()
function docstring for more information.
Total running time of the script: (0 minutes 0.212 seconds)