Visualizing waste generation with LightningChart Python

Tutorial

Assisted by AI

Data Visualization Analysis of Ireland Waste Generation from 2004 to 2020 with LightningChart Python.
Fateme Ajam

Fateme Ajam

Data Science Python Developer

LinkedIn icon
Waste-generation-Cover

Introduction

Waste management has become an increasingly critical issue as global industries and households generate vast amounts of waste annually. This article leverages a detailed dataset on waste generation across various economic activities and industries, providing insights into trends and patterns in waste production.

By utilizing advanced visualization tools such as LightningChart Python, this study identifies key contributors to waste, evaluates temporal fluctuations, and explores the impact of waste management policies. Through this analysis, we aim to uncover areas requiring targeted interventions and propose sustainable solutions to mitigate waste generation.

About the Dataset

The dataset provides detailed information on waste generation across various economic activities and waste categories over multiple years. It categorizes waste by industry sectors and specific waste types, offering a comprehensive view of waste production trends.

This dataset is invaluable for analyzing the dynamics of waste management, identifying major contributors to waste production, and evaluating the impact of policies aimed at reducing waste. Policymakers and researchers can leverage this data to design targeted strategies for sustainable waste management and monitor progress in minimizing waste generation.

LightningChart Python

LightningChart Python was chosen as the primary visualization tool due to its exceptional performance in handling large datasets and creating real-time interactive visualizations. Its capabilities include:

  1. Seamless Data Handling: Processes millions of data points without performance degradation.
  2. Real-Time Updates: Facilitates dynamic visualization, making it ideal for time-series and comparative analyses.
  3. Customizability: Offers a wide range of chart types, enabling tailored visualizations for specific insights.
LCPython1

Chart Types Used in the Waste Management Project

In this project, we use various chart types from LightningChart Python to analyze and visualize waste production and management trends effectively:

  • Line Charts: Line charts depict trends in waste production over time across different activities. For example, they highlight the consistent growth in household waste and the rise of industrial contributions.
  • Area Charts: Area charts show the total waste produced by top activities, such as batteries and accumulators. These charts effectively highlight major peaks and declines in waste generation. 
  • 3D Box Charts: 3D box charts provide a visual representation of waste contributions by the top five activities across multiple years. The combination of spatial dimensions and color gradients allows for an intuitive understanding of waste intensity and trends. 
  • TreeMap Charts: Tree maps visualize the distribution of total waste across activities and industries. For instance, healthcare waste contributions are mapped out, illustrating their dominance among certain activities. 
  • Polar Heatmaps: Polar heatmaps represent waste intensity for various activities and hazardousness levels, offering a circular view of data for a unique comparative perspective. 
  • Polar Line Charts: Polar line charts illustrate annual trends in hazardous and non-hazardous waste production, highlighting fluctuations and dominant waste types over the years. 
  • Polar Area Charts: Polar area charts show the relative contributions of economic activities to total waste production over time, emphasizing the shifts in industries’ roles.
  • Dashboards: Dashboards integrate multiple visualizations into a cohesive view, combining trends, contributions, and patterns to provide a holistic understanding of waste management.

Optimizing Data Visualization Performance

The project required efficient visualization of large datasets spanning decades and multiple activities. LightningChart Python proved to be an exceptional tool for handling this complexity due to its advanced visualization capabilities.

Setting Up Python Environment

To begin working on this project, it’s necessary to install the required libraries, including Pandas and LightningChart Python. You can do this by following the steps below:

  1. First, you need to install Python: Download and install the latest version of Python from the official Python website.
  2. Second, you need to Install Pandas and LightningChart:

Use the pip package manager to install the necessary libraries by running these commands:

pip install lightningchart
pip install pandas numpy

Visualizing Data with LightningChart Python

LightningChart provides an advanced platform for visualizing intricate datasets effectively. Here, we delve into various visualizations to uncover trends and patterns in waste production and management across industries and activities.

1. Line Chart: Trends of Selected Activities (Acid, Alkaline, or Saline Wastes)

The trends represent the production of acid, alkaline, or saline wastes (W012) across different sectors over time. The dataset aggregates values for waste output from various activities, including households and industries such as manufacturing and specific sub-sectors like chemical production and electronics.

The TOTAL_HH sector, representing all household-related activities, contributes the highest amount of waste, showing a significant rise around 2010 and consistent growth after 2012. This indicates that households are a major source of such waste.

On the other hand, industrial activities like C20-C22 (chemical manufacturing) and C31-C33 (furniture and machinery) show steady increases in waste production, reflecting industrial growth. Some sectors, like C10-C12 (food and beverage manufacturing) and C26-C30 (electronics and transport equipment), produce relatively stable waste amounts, with minor variations.

lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name='Unpivoted')
filtered_data = data[
    (data['VALUE'] != 0) & 
    (data['VALUE'].notnull()) & 
    (data['Waste Category'] == 'Acid, alkaline or saline wastes[W012]')
]

selected_activities = [
    'TOTAL_HH', 'C', 'C20-C22', 'C10-C12', 'C26-C30', 'C31-C33'
]
filtered_activities = filtered_data.groupby(["Year", "NACE Rev. 2 Activity"])["VALUE"].sum().unstack()[selected_activities]

chart = lc.ChartXY(theme=lc.Themes.Dark, title="Selected Activities Trends")
for activity in filtered_activities.columns:
    chart.add_spline_series().set_name(activity).append_samples(
        filtered_activities.index.tolist(), filtered_activities[activity].fillna(0).tolist()
    )

chart.get_default_x_axis().set_title("Year").set_interval(filtered_activities.index.min(), filtered_activities.index.max())
chart.get_default_y_axis().set_title("Value")
chart.set_mouse_interaction_wheel_zoom(True)
chart.open()
waste-generation-line-chart

This analysis highlights the need for targeted waste management policies. The focus should be on reducing household waste, which dominates, while also addressing industrial sectors with rising trends to ensure sustainable waste management practices.

2. Area Chart: Total Waste Trends by Top Industries (Batteries and Accumulators)

This chart shows the production of battery and accumulator waste (W0841) in five key industries from 2004 to 2020. The X-axis represents the years, and the Y-axis shows the total waste in Tonnes.

The household sector (TOTAL_HH) produces the highest waste, with a sharp peak in 2018 before declining significantly. Other sectors, such as waste management (E38), contribute less but remain consistent over time.

lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name='Unpivoted')
filtered_data = data[
    (data['VALUE'] != 0) & 
    (data['VALUE'].notnull()) & 
    (data['Waste Category'] == 'Batteries and accumulators wastes[W0841]')
]

top_activities = filtered_data.groupby('NACE Rev. 2 Activity')['VALUE'].sum().nlargest(5).index
filtered_data = filtered_data[filtered_data['NACE Rev. 2 Activity'].isin(top_activities)]
grouped_data = filtered_data.groupby(["Year", "NACE Rev. 2 Activity"])["VALUE"].sum().unstack()

chart = lc.ChartXY(theme=lc.Themes.Dark, title="Total Waste (Tonnes)")
for activity, values in grouped_data.items():
    chart.add_area_series().set_name(activity).add(grouped_data.index.tolist(), values.fillna(0).tolist())

chart.get_default_x_axis().set_title("Year").set_tick_strategy('Empty')
chart.get_default_y_axis().set_title("Value (Tonnes)")
chart.add_legend()
chart.open()
waste-generation-area-chart

The dominance of household waste highlights the need for better recycling systems and policies to manage battery disposal effectively. The 2018 spike suggests a possible policy shift or increased usage, emphasizing the importance of monitoring such trends.

Industrial waste remains stable, reflecting controlled practices. Overall, the chart highlights the critical role of households and the need for targeted waste management strategies.

3. 3D Box Chart: Chemical Waste Generation by Top Activities Over Time

This 3D chart illustrates the total chemical waste (W02A) generated by the top five activities from 2004 to 2020. The X-axis represents the years, the Y-axis shows the total waste value, and the Z-axis lists the activities. A color gradient, from blue (lowest) to red (highest), highlights the magnitude of waste.

lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name='Unpivoted')
filtered_data = data[
    (data['VALUE'] != 0) & 
    (data['VALUE'].notnull()) & 
    (data['Waste Category'] == 'Chemical wastes[W02A]')
]

top_activities = filtered_data.groupby('NACE Rev. 2 Activity')['VALUE'].sum().nlargest(5).index
filtered_data = filtered_data[filtered_data['NACE Rev. 2 Activity'].isin(top_activities)]
activities = [activity.split('(')[-1].strip(')') for activity in top_activities]
years = sorted(filtered_data['Year'].unique())

chart = lc.Chart3D(theme=lc.Themes.Dark, title="Top 5 Activities by Total Waste Value")
chart.get_default_x_axis().set_title("Year").set_interval(min(years), max(years))
chart.get_default_z_axis().set_title("Activity").set_interval(0, len(activities) - 1)

for year in years:
    chart.get_default_x_axis().add_custom_tick().set_value(year).set_text(str(year))
for i, activity in enumerate(activities):
    chart.get_default_z_axis().add_custom_tick().set_value(i).set_text(activity)

boxes = [
    {
        'xCenter': float(year),
        'yCenter': value / 2,
        'zCenter': activities.index(activity.split('(')[-1].strip(')')),
        'xSize': 2,
        'ySize': value,
        'zSize': 1
    }
    for activity, group in filtered_data.groupby('NACE Rev. 2 Activity')
    for year, value in group.groupby('Year')['VALUE'].sum().items()
]

chart.add_box_series().set_palette_coloring(
    steps=[
        {'value': 0.0, 'color': lc.Color('blue')},
        {'value': 0.25, 'color': lc.Color('yellow')},
        {'value': 0.5, 'color': lc.Color('green')},
        {'value': 0.75, 'color': lc.Color('orange')},
        {'value': 1.0, 'color': lc.Color('red')}
    ],
    percentage_values=True
).add(boxes)

chart.add_legend()
chart.open()
waste-generation-3d-box-chart

The chart reveals a sharp peak in 2014, indicating an exceptional increase in chemical waste for certain activities. This could be linked to industrial growth or changes in waste reporting or management policies. Other activities display relatively stable waste levels across the years, with no significant fluctuations.

The 2014 spike emphasizes the need to investigate specific causes and address them through targeted waste management strategies. Meanwhile, the stable activities suggest opportunities to further optimize and sustain current waste handling practices.

4. Dashboard

This dashboard combines the previously analyzed charts into a single view, providing a comprehensive visual summary of waste trends across different categories and activities over time. It integrates the trends of acid, alkaline, or saline wastes, chemical waste contributors, and battery-related waste activities, allowing for a holistic analysis in one place.

lc.set_license(open('license-key').read().strip())

dashboard = lc.Dashboard(rows=2, columns=2, theme=lc.Themes.TurquoiseHexagon)

# Chart 1: Trends of Selected Activities (Acid, Alkaline, or Saline Wastes)
chart1 = dashboard.ChartXY(row_index=0, column_index=0, column_span=2, title="Trends of Selected Activities")
chart1.set_title_position("center-top")

# Chart 2: Total Waste from Top Activities (Batteries and Accumulators) chart2 = dashboard.ChartXY(column_index=1, row_index=1, title="Total Waste from Top Activities")
chart2.set_title_position("center-top")

# Chart 3: Top 5 Activities (Chemical Wastes) chart3 = dashboard.Chart3D(column_index=0, row_index=1, title="Top 5 Activities (Chemical Wastes)")

dashboard.open()
waste-generation-dashboard

5. TreeMap: Healthcare and Biological Waste Distribution Across Activities

This TreeMap chart shows the distribution of healthcare and biological waste (W05) across various activities from 2004 to 2020. Each year is represented as a distinct section, with activities nested within based on their contributions to total waste. Larger boxes indicate higher waste values, while the color gradient, ranging from blue (low) to red (high), highlights the magnitude of waste for each activity.

lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name='Unpivoted')
filtered_data = data[
    (data['VALUE'] != 0) & 
    (data['VALUE'].notnull()) & 
    (data['Waste Category'] == 'Health care and biological wastes[W05]') & 
    (data['Hazardousness'] != 'Hazardous and non-hazardous - Total[HAZ_NHAZ]')
]

aggregated_data = filtered_data.groupby(["Year", "NACE Rev. 2 Activity"], as_index=False).agg({"VALUE": "sum"})
treemap_data_aggregated = [
    {
        "name": str(year),
        "children": [
            {"name": activity, "value": value}
            for activity, value in zip(year_group["NACE Rev. 2 Activity"], year_group["VALUE"])
        ]
    }
    for year, year_group in aggregated_data.groupby("Year")
]

chart = lc.TreeMapChart(theme=lc.Themes.Dark, title="Health Care and Biological Wastes by Year")
chart.set_data(treemap_data_aggregated)

min_value, max_value = aggregated_data["VALUE"].min(), aggregated_data["VALUE"].max()
chart.set_node_coloring(
    steps=[
        {"value": min_value, "color": lc.Color("blue")},
        {"value": (min_value + max_value) / 4, "color": lc.Color("green")},
        {"value": (min_value + max_value) / 2, "color": lc.Color("yellow")},
        {"value": (3 * (min_value + max_value)) / 4, "color": lc.Color("orange")},
        {"value": max_value, "color": lc.Color("red")}
    ]
)

chart.add_legend().set_position(10, 20)
chart.open()
waste-generation-treemap

The chart reveals that the All activities plus households (TOTAL_HH) category consistently dominates in most years, reflecting its significant contribution to healthcare waste. Other activities, such as services and manufacturing, show smaller but noticeable contributions. Peaks in certain years, like 2016 and 2018, suggest shifts in waste production patterns, likely influenced by increased healthcare activity or waste reporting changes.

This visualization provides an effective way to track and compare waste contributions over time, highlighting key areas for waste reduction and management.

6. Multi-Line Dashboard: Waste Trends Across Activities (2004–2020)

This dashboard presents multiple line charts, each visualizing waste trends for specific activities from 2004 to 2020. Each chart represents a unique activity, with the Y-axis showing waste values in millions and the X-axis representing years.

lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name='Unpivoted')
activities = data.groupby(["Year", "NACE Rev. 2 Activity"])["VALUE"].sum().unstack() / 1e6

years = activities.index.tolist()
titles = [activity.split("(")[-1].strip(")") for activity in activities.columns]

dashboard = lc.Dashboard(columns=4, rows=5, theme=lc.Themes.Dark)

for i, (activity, title) in enumerate(zip(activities.columns, titles)):
    chart = dashboard.ChartXY(column_index=i % 4, row_index=i // 4, title=title)
    chart.add_area_series(data_pattern="ProgressiveX").append_samples(years, activities[activity].fillna(0).tolist())
    chart.get_default_x_axis().set_tick_strategy('Empty').set_interval(min(years), max(years))
    chart.get_default_y_axis().set_title("Value (Millions)" if i % 4 == 0 else "")

dashboard.open()
waste-generation-multi-line-dashboard

The charts reveal varying patterns across activities:

  1. TOTAL_HH: A significant decline after 2004, followed by stability at lower values.
  2. Industrial Activities (C, F, B): Show sharp peaks around 2016, reflecting a temporary increase in waste production.
  3. Specialized Manufacturing (C24_C25, C26_C30): Consistent growth over time, suggesting rising industrial activity in these sectors.
  4. Other Activities: Smaller contributions, with fluctuations but no significant growth trends.

This dashboard allows for a detailed comparison of waste trends across activities, highlighting key contributors and shifts over time. It serves as a valuable tool for identifying areas requiring focused waste management strategies.

7. TreeMap Chart: Total Wastes by Activity (Percentage Contribution)

This TreeMap chart visualizes the distribution of total waste by various industrial and household activities. Each activity is represented by a box, with its size corresponding to its total waste value and the color indicating its relative contribution. Warmer colors (e.g., red) denote higher waste contributions, while cooler colors (e.g., blue) indicate lower values.

lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name='Unpivoted')
filtered_data = data[
    (data['VALUE'] != 0) & 
    (data['VALUE'].notnull()) & 
    (data['Hazardousness'] != 'Hazardous and non-hazardous - Total[HAZ_NHAZ]') & 
    (data['NACE Rev. 2 Activity'] != 'All NACE activities plus households (TOTAL_HH)')
]

aggregated_data = filtered_data.groupby("NACE Rev. 2 Activity", as_index=False).agg({"VALUE": "sum"})
aggregated_data['Percentage'] = (aggregated_data['VALUE'] / aggregated_data['VALUE'].sum()) * 100

treemap_data_no_year = [
    {"name": f"{activity} ({percent:.1f}%)", "value": value}
    for activity, value, percent in zip(
        aggregated_data["NACE Rev. 2 Activity"],
        aggregated_data["VALUE"],
        aggregated_data["Percentage"]
    )
]

chart = lc.TreeMapChart(theme=lc.Themes.Dark, title="Total Wastes by Activity")
chart.set_data(treemap_data_no_year)

chart.set_node_coloring(
    steps=[
        {"value": aggregated_data["VALUE"].min(), "color": lc.Color("blue")},
        {"value": aggregated_data["VALUE"].max() / 4, "color": lc.Color("green")},
        {"value": aggregated_data["VALUE"].max() / 2, "color": lc.Color("yellow")},
        {"value": (3 * aggregated_data["VALUE"].max()) / 4, "color": lc.Color("orange")},
        {"value": aggregated_data["VALUE"].max(), "color": lc.Color("red")}
    ]
)

chart.add_legend()
chart.open()
waste-generation-treemap-total-waste

From the dataset, construction (F) is the largest contributor, accounting for 26.2% of the total waste, followed by manufacturing (C) at 15.2%. Mining and quarrying (B) and households (EP_HH) also contribute significantly, while smaller activities are represented in green and blue.

The chart provides a clear overview of the dominant activities generating waste, emphasizing the major contributors and their percentage share. This visualization is useful for identifying priority areas for waste reduction and management strategies.

Polar Analysis Dashboard: Waste Intensity, Trends, and Contributions

This dashboard provides a comprehensive visualization of waste production data across economic activities, waste types, and time. It uses four Polar Charts to explore different dimensions of the dataset.

  • Waste Intensity by Activities and Hazard Types: The top-left chart visualizes the intensity of waste production by various economic activities (NACE Rev. 2 Activity) and types of waste (Hazardous and Non-Hazardous). The heatmap demonstrates how specific activities dominate in waste production, with color gradients highlighting high-intensity areas.
  • Trends in Waste Production (Hazardous vs. Non-Hazardous): The top-right chart shows annual trends in hazardous and non-hazardous waste production. Hazardous waste is consistently higher, with both types displaying fluctuations over time, emphasizing the need to address hazardous waste specifically.
  • Yearly Waste Intensity by Hazardousness: The bottom-left chart captures waste intensity trends over the years for hazardous and non-hazardous waste. Peaks in specific years reflect periods of increased production, possibly due to industrial activity or policy changes.
  • Relative Contributions of Economic Activities: The bottom-right chart illustrates the percentage share of waste contributions by economic activities over time. The chart reveals which industries consistently contribute the most, showing variability in their relative shares.
lc.set_license(open('license-key').read().strip())

data = pd.read_excel('dataset/Batteries.xlsx', sheet_name="Unpivoted")
dashboard = lc.Dashboard(columns=2, rows=2, theme=lc.Themes.TurquoiseHexagon)

# Chart 1: Intensity of Waste by Economic Activities
filtered_data = data[(data["Waste Category"] == "Batteries and accumulators wastes[W0841]") & 
                     (~data["NACE Rev. 2 Activity"].str.contains("TOTAL_HH", na=False))]
heatmap_data = filtered_data.pivot_table(index='Hazardousness', columns='NACE Rev. 2 Activity', values='VALUE', aggfunc='sum', fill_value=0)

chart = dashboard.PolarChart(0, 0).set_title("Waste Intensity by Activities")
heatmap_series = chart.add_heatmap_series(sectors=len(heatmap_data.columns), annuli=len(heatmap_data.index))
heatmap_series.invalidate_intensity_values(values=heatmap_data.values.tolist())
chart.add_legend().add(heatmap_series.set_palette_coloring([
    {'value': heatmap_data.values.min(), 'color': lc.Color('blue')},
    {'value': heatmap_data.values.max(), 'color': lc.Color('red')}
]))

# Chart 2: Trends of Hazardous and Non-Hazardous Waste
filtered_data = filtered_data[filtered_data['Hazardousness'].isin(['Hazardous[HAZ]', 'Non-hazardous[NHAZ]'])]
grouped_data = filtered_data.groupby(['Year', 'Hazardousness'])['VALUE'].sum().unstack()

chart = dashboard.PolarChart(1, 0).set_title("Hazardous vs. Non-Hazardous Waste")
for waste_type, color in {'Hazardous[HAZ]': 'red', 'Non-hazardous[NHAZ]': 'blue'}.items():
    data_points = [{'angle': np.interp(year, [grouped_data.index.min(), grouped_data.index.max()], [0, 360]), 
                    'amplitude': grouped_data.loc[year, waste_type]} for year in grouped_data.index if waste_type in grouped_data.columns]
    chart.add_point_line_series().set_name(waste_type).set_stroke(2, lc.Color(color)).set_data(data_points)
chart.add_legend()

# Chart 3: Yearly Waste Intensity by Hazardousness
intensity_values = [
    [grouped_data.loc[year, waste_type] if waste_type in grouped_data.columns else 0 
     for year in grouped_data.index] for waste_type in ['Hazardous[HAZ]', 'Non-hazardous[NHAZ]']
]

chart = dashboard.PolarChart(0, 1).set_title("Yearly Intensity by Hazardousness")
heatmap_series = chart.add_heatmap_series(sectors=len(grouped_data.index), annuli=2)
heatmap_series.invalidate_intensity_values(values=intensity_values)
chart.add_legend().add(heatmap_series.set_palette_coloring([
    {'value': 0, 'color': lc.Color('blue')},
    {'value': max(map(max, intensity_values)), 'color': lc.Color('red')}
]))

# Chart 4: Relative Contributions of Economic Activities
grouped_data = filtered_data.groupby(['Year', 'NACE Rev. 2 Activity'])['VALUE'].sum().unstack()
normalized_data = grouped_data.div(grouped_data.sum(axis=1), axis=0).fillna(0)

chart = dashboard.PolarChart(1, 1).set_title("Relative Contributions of Activities")
for activity in grouped_data.columns:
    data_points = [{'angle': np.interp(year, [grouped_data.index.min(), grouped_data.index.max()], [0, 360]), 
                    'amplitude': normalized_data.loc[year, activity]} for year in grouped_data.index]
    chart.add_area_series().set_name(activity).set_stroke(2, lc.Color(f'#{random.randint(0, 0xFFFFFF):06x}')).set_data(data_points)
chart.add_legend()

dashboard.open()
waste-generation-polar-dashboard

This dashboard highlights key insights into waste management challenges, identifying dominant contributors and temporal shifts, enabling targeted strategies for mitigation.

Conclusion

The analysis of waste management trends presented in this article highlights the pressing need for enhanced waste management strategies. Industries such as manufacturing, healthcare, and households emerge as significant contributors to waste production, underscoring the importance of sector-specific policies.

The visualizations provide a clear perspective on the temporal and spatial distribution of waste, revealing peaks linked to industrial growth and policy changes. By addressing dominant waste-generating sectors and promoting sustainable practices, policymakers and stakeholders can work towards reducing the environmental impact of waste while fostering a more sustainable future.

Continue learning with LightningChart