Note
Go to the end to download the full example code.
Bar Line Charts¶
Bar-line charts, which combine bar charts and line charts, can be generated using the fig_bar_line_chart() function, which returns a Plotly Go Figure object.
The plot below was generated using a synthetic dataset of monthly and 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_line.csv file).
Month-Year |
Patient Enrolment |
Cumulative Patient Enrolment |
|---|---|---|
January 2026 |
2 |
2 |
February 2026 |
8 |
10 |
March 2026 |
50 |
60 |
April 2026 |
20 |
80 |
May 2026 |
15 |
95 |
June 2026 |
5 |
100 |
In addition to the data(frame) itself, note some of the other key columns required for the fig_bar_line() function:
"xlabel"- thex-axis label"ylabel_left"- the lefty-axis label, which should correspond to the bar column (see below)"ylabel_right"- the righty-axis label, which should correspond to the line column (see below)"bar_column"- the column representing the bar values, which should be labelled with"ylabel_left""line_column"- the column representing the line values, which should be labelled with"ylabel_right"
Here are the Python steps you need to generate the plot using the fig_bar_line_chart() function:
48 import pandas as pd
49 from isaricanalytics.visualisation import fig_bar_line_chart
50
51 # Load the CSV
52 data = pd.read_csv("./csv/bar_line.csv")
53
54 # Create and display the figure
55 fig = fig_bar_line_chart(
56 data,
57 title="Bar-Line Chart of Monthly and Cumulative Patient Enrolment",
58 xlabel="Month-Year",
59 ylabel_left="Cumulative Patients Enrolled",
60 ylabel_right="Patients Enrolled",
61 bar_column="cum_patients_enrolled",
62 line_column="patients_enrolled",
63 index_column="month_year"
64 )
65 fig.update_layout(autosize=True)
66 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 0.218 seconds)