Note
Go to the end to download the full example code.
Bar Charts¶
Ordinary bar charts can be generated using the fig_bar_chart() function, which returns a Plotly Go Figure object.
The plot below was generated using a synthetic dataset of cumulative patient enrolment data for a clinical site.
The dataset is given below as a table (but can also be loaded from the static examples/csv/bar.csv file).
Month-Year |
Cumultative Patient Enrolment |
|---|---|
January 2026 |
2 |
February 2026 |
10 |
March 2026 |
60 |
April 2026 |
80 |
May 2026 |
95 |
June 2026 |
100 |
Here are the Python steps you need to generate the plot using the fig_bar_chart() function:
33 import pandas as pd
34 from isaricanalytics.visualisation import fig_bar_chart
35
36 # Load the CSV
37 data = pd.read_csv("./csv/bar.csv")
38
39 # Create and display the figure
40 fig = fig_bar_chart(
41 data,
42 title="Bar Chart of Cumulative Patient Enrolment",
43 xlabel="Month-Year",
44 ylabel="Cumulative Patients Enrolled",
45 index_column="month_year"
46 )
47 fig.update_layout(autosize=True)
48 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_sunburst()
function docstring for more information.
Total running time of the script: (0 minutes 13.681 seconds)