LightningChart PythonChronic Disease Visualization in Python

TutorialImplementation of a chronic disease visualization data application with LightningChart Python.

Written by a human | Updated on April 23rd, 2025

Chronic Disease Visualization in Python

Predictive analytics nowadays play a huge role in the healthcare system. In the US, nearly 90% of resources spent on healthcare go on managing chronic diseases, including diabetes. Thus, it is an important topic to consider when working on medical data.

LightningChart Python

Feature-image---lcpy-social-media

For this task, we may use the LightningChart Python library. It provides a wide range of tools for creating graphs that can be useful for the chronic disease visualization application in Python. In this project, we will use:

LightningChart provides easily-to-initialize charts that are also easily and widely customizable, so we will use this library for the visualizations.

Setting Up Python Environment

To create a chronic disease visualization in Python, first, we need to set up our Python environment.

1. The first step is installing Homebrew itself

I recommend using Homebrew package manager as it is popular and has a lot of packages. Moreover, it is arguably more convenient than installing Python using .dmg. You can skip this step if it is already installed on your Mac. Enter Terminal app and copy/paste this string:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Important note: the installation of Homebrew is not fast, it usually takes between 5 to 15 minutes.

2. Installation of Python

This command will install the latest stable version of Python. 

brew install python

NOTE: if you don’t want to use Homebrew, you can access the official Python website, select the latest stable version downloader for MacOS (its named macOS 64-bit universal2 installer), and follow the installation instructions. You can check the version using python3 –version in the terminal. If it displays Unknown command error, it is most likely due to PATH variables. Refer to this guide to fix it.

Installation of Python on Windows

I recommend using the tool Winget. To install the Python package, open cmd or PowerShell as Administrator and type:

winget install Python.Python.3

NOTE: if you don’t want to use Winget, You can access the official Python website, select the latest stable version downloader for Windows
(it is named Windows installer (64-bit)) and follow the installation instructions. You can verify the installation of Python and pip by typing python --version and pip --version respectively. If it displays command' is not recognized error, it is most likely due to PATH variables. Refer to this guide to fix.

3. Installation of IDE

For IDE (integrated development environment), I recommend using PyCharm as it is clean and powerful. However, the full version is paid so you can also use VSCode. Optionally, you may want to set up Venv (Python virtual environment) to install packages there and not clutter the Python installation. The environment-creating instructions are:

4. Setting up jupyter notebook

For PyCharm (ONLY PROFESSIONAL VERSION): Just create an .ipynb file and start coding. The IDE will install everything needed on its own.

ipynb_create

For Visual Studio Code

  • Install Jupyter extension:
jupyter_extension
  • Select and open the working directory
  • Create venv (⇧⌘P or Ctrl-⇧-P). Very recommended!
  • Refer to the following article (starting from “Workspace Trust” paragraph)

5. Libraries Used

  • Jupyter: A very nice library for data analysis, supports both executable code blocks and markdown blocks. With it, you can create clear and visual analysis reports.
  • Pandas: In this project, we will mainly use the two-dimensional data frame data structure provided by Pandas. It can be easily created from a .CSV or Excel file.
  • LightningChart: LightningChart is the main library used in the project for creating different types of charts in Python. It provides highly customizable graph-building tools, including simple XY charts, 3D charts, Bar charts, Spider charts, and Map charts.

6. Installing and importing libraries

Type in terminal to install libraries:

pip install pandas lightningchart

Then, when started coding, write this code to import these libraries:

import pandas as pd
pd.options.mode.chained_assignment = None
import lightningchart as lc

Handling and Processing Data

Note that you can see the complete code inside .ipynb files in GitHub, here will be the summary. 

Reading data from the csv file

The file with data is contained under /data folder.

df = pd.read_csv("data/diabetes.csv")
df  # this will display the dataframe after cell

Deleting irrelevant entries

Firstly, we need to delete invalid entries where there is an error (the values are 0):

df = df[(df['Glucose'] != 0) & (df['Insulin'] != 0) & (df['BMI'] != 0)]

Dividing age into bins

We need to assign each entry a relevant age bin (we will need it later):

ages = df["Age"]
print("Min age: ", min(ages), "\nMax: ", max(ages))

Output:

Min age:  21 
Max:  81
bins = [20, 30, 50, 81]  
labels = ['21-30', '31-50', '51-81']

df["Age_range"] = pd.cut(df["Age"], bins=bins, labels=labels, right=True)
df["Outcome_label"] = df["Outcome"].replace({0: 'Diabetes Negative', 1: 'Diabetes Positive'})

df

Output:

     Pregnancies  Glucose  BloodPressure  SkinThickness  Insulin   BMI  \
3              1       89             66             23       94  28.1   
4              0      137             40             35      168  43.1   
6              3       78             50             32       88  31.0   
8              2      197             70             45      543  30.5   
13             1      189             60             23      846  30.1   
..           ...      ...            ...            ...      ...   ...   
753            0      181             88             44      510  43.3   
755            1      128             88             39      110  36.5   
760            2       88             58             26       16  28.4   
763           10      101             76             48      180  32.9   
765            5      121             72             23      112  26.2   

     DiabetesPedigreeFunction  Age  Outcome Age_range      Outcome_label  
3                       0.167   21        0     21-30  Diabetes Negative  
4                       2.288   33        1     31-50  Diabetes Positive  
6                       0.248   26        1     21-30  Diabetes Positive  
8                       0.158   53        1     51-81  Diabetes Positive  
13                      0.398   59        1     51-81  Diabetes Positive  
..                        ...  ...      ...       ...                ...  
753                     0.222   26        1     21-30  Diabetes Positive  
755                     1.057   37        1     31-50  Diabetes Positive  
760                     0.766   22        0     21-30  Diabetes Negative  
763                     0.171   63        0     51-81  Diabetes Negative  
765                     0.245   30        0     21-30  Diabetes Negative  

[392 rows x 11 columns]

Dividing into 2 tables based on the outcome

We also need to divide our dataframe into two for our convinience later:

df_negative = df[df['Outcome'] == 0]
df_positive = df[df['Outcome'] == 1]

Scatter chart (BMI vs Glucose)

glucose_negative = df_negative["Glucose"].tolist()  # get data columns from tables
BMI_negative = df_negative["BMI"].tolist()

glucose_positive = df_positive["Glucose"].tolist()
BMI_positive = df_positive["BMI"].tolist()

scatter = lc.ChartXY(   # scatter chart intialization
    theme=lc.Themes.White,  # overall theme
    title='Scatter Chart (BMI vs Glucose)', 
)
series_negative = scatter.add_point_series().add(
    x=BMI_negative,  # push samples to series
    y=glucose_negative,
)
series_positive = scatter.add_point_series().add(
    x=BMI_positive,  
    y=glucose_positive,
)

# Set colors of dots and names of the series
series_negative.set_point_color(lc.Color(0, 255, 0, 192)).set_name("Diabetes Negative")
series_positive.set_point_color(lc.Color(255, 0, 0, 192)).set_name("Diabetes Positive")

# Set titles of axis 
scatter.get_default_x_axis().set_title("BMI")
scatter.get_default_y_axis().set_title("Glucose")
scatter.add_legend().add(scatter)
scatter.open()
chronic-disease-visualization-scatter-chart-bmi-versus-glucose

Analysis

By looking at this chart the correlation between these two characteristics and the disease is visible. Those with high Glucose and BMI are more likely to have diabetes. However, high glucose numbers contribute to the diagnosis more than BMI. Also, those with low BMI usually have lower glucose levels.

3D Chart Version

Try to create a 3D chart (x = BMI, y = Glucose, z = Age) yourself, if you wish. Refer to this Python 3D charts guide.

age_negative = df_negative["Age"].tolist()  # ages to list
age_positive = df_positive["Age"].tolist()

scatter3d = lc.Chart3D(  # 3d chart instance
    theme=lc.Themes.White,
    title='Chart 3D',
)

series_negative = scatter3d.add_point_series(render_2d=False).add(
    x=BMI_negative,
    y=glucose_negative,
    z=age_negative
)
series_positive = scatter3d.add_point_series(render_2d=False).add(
    x=BMI_positive,
    y=glucose_positive,
    z=age_positive
)

series_negative.set_point_color(lc.Color(0, 255, 0, 192)).set_name("Diabetes Negative")
series_positive.set_point_color(lc.Color(255, 0, 0, 192)).set_name("Diabetes Positive")


scatter3d.get_default_x_axis().set_title("BMI")  
scatter3d.get_default_y_axis().set_title("Glucose")
scatter3d.get_default_z_axis().set_title("Age")
scatter3d.add_legend().add(scatter3d)
scatter3d.open()

Analysis

Age seems not to contribute so much to the outcome, we can check it by using the Bar Chart

Stacked Bar Chart

outcome_counts = df.groupby(['Age_range', 'Outcome_label'], observed=True).size().unstack(fill_value=0).reset_index()  # ages to columns

result = []
for outcome_label in ['Diabetes Negative', 'Diabetes Positive']:  # make json-like formation of data
    values = outcome_counts[outcome_label].tolist()   
    result.append({                     
        'subCategory': outcome_label,
        'values': values
    })
    
barchart_stacked = lc.BarChart(  # initialize bar chart
    vertical=True,
    theme=lc.Themes.White,
    title='Stacked Bar Chart',
).set_value_label_display_mode('insideBar')  # count of entries is inside bar, default - outside
barchart_stacked.set_data_stacked(labels, result)  # set data
barchart_stacked.add_legend().add(barchart_stacked)  # add legend
barchart_stacked.open()
chronic-disease-visualization-stacked-bar-chart

Analysis

Though the age groups (31-50) and (51-81) aren’t as numerical as (21-30), percentage-wise we can say that the older the person, the higher the risk of diabetes.

Box Plot

Let’s look at the numbers of glucose for diabetes-negative patients and diabetes-positive.

glucose_diabetes = df_positive['Glucose'].values  # divide entries by diabetes
glucose_no_diabetes = df_negative['Glucose'].values

boxplt = lc.BoxPlot(  # init bax plot
    data=[glucose_no_diabetes, glucose_diabetes],
    theme=lc.Themes.White,
    title='Glucose',
    xlabel='No diabetes (left), Diabetes positive (right)',
    ylabel='Glucose'
)
boxplt.open()
chronic-disease-visualization-box-plot

Analysis

This supports the tendency we saw in scatter plot: Diabetes-positive patients have higher levels of glucose.

Additional Box Plot (Number of pregnancies)

Let’s explore the correlation between pregnancies and diabetes:

pregnancies_diabetes = df_positive['Pregnancies'].values
pregnancies_no_diabetes = df_negative['Pregnancies'].values

boxplt1 = lc.BoxPlot(
    data=[pregnancies_no_diabetes, pregnancies_diabetes],
    theme=lc.Themes.White,
    title='Pregnancies',
    xlabel='No diabetes (left), Diabetes positive (right)',
    ylabel='Pregnancies'
)
boxplt1.open()
chronic-disease-visualization-box-plot-number-of-pregnancies

Analysis

Most likely diabetes depends on the number of pregnancies, but the dependence is not that strong.

Conclusion

In this guide, we did a chronic disease visualization in Python. We used Jupyter Notebook along with libraries lightningchart and pandas.

Benefits of using LightningChart

LightningChart provides a lot of ready-made options for creating graphs. Otherwise, we would have a headache creating proper charts for the Python chronic disease visualization, whilst LightningChart has powerful tools to create XY charts with a huge amount of points in almost no time.

There are lots of other tools in the library, you can review various code snippets for different tasks at LightningChart Python Guide.

Georgii Gibizov

Georgii Gibizov

Data Science Python Developer

LinkedIn icon
divider-light

Continue learning with LightningChart

Best ApexCharts Alternatives in 2026: Scale Beyond SVG, Add Real 3D

Best ApexCharts Alternatives in 2026: Scale Beyond SVG, Add Real 3D

ApexCharts earned its position through a set of genuine strengths executed consistently well: MIT license, the best default visual aesthetics among free JavaScript chart libraries, official and actively maintained React, Vue, and Angular component wrappers, clean...

Best amCharts Alternatives in 2026: No Watermark, Faster, Real 3D

Best amCharts Alternatives in 2026: No Watermark, Faster, Real 3D

amCharts 5 wins on visual aesthetics. The default chart transitions are among the smoothest in the JavaScript charting space, the animation quality is a genuine differentiator, and the chart type range Gantt charts, flowcharts, geographic maps, financial OHLC, Sankey...