Skip to main content

Real-time data

Visualizing real-time data with LightningChart Python is extremely simple. The only practical differences from the static display mode are:

  • Chart must be opened with the parameter live=True
  • Real-time updates must be applied after the chart has been opened
  • Chart must be closed manually by chart.close()
import lightningchart as lc
import random
import time

lc.set_license('my-license-key')

chart = lc.ChartXY(title='Real-time scatter chart')
chart.set_animations_enabled(False)
series = chart.add_point_series()
chart.get_default_x_axis().set_interval(0, 100, stop_axis_after=True)
chart.get_default_y_axis().set_interval(0, 100, stop_axis_after=True)
chart.open(live=True)

# Generate random scatter data and add it to the chart
for i in range(1000):
x = random.uniform(0, 100)
y = random.uniform(0, 100)
series.add(x, y)
time.sleep(0.01)

chart.close()
Real-time scatter chartReal-time scatter chart

Scrolling charts

Many real-time data visualization use cases require the axis of the chart to scroll to account for the new data points. To enable this, the desired axis' scroll strategy must be set to progressive. It is also recommended to configure appropriate axis interval (start and end points) with the additional flag stop_axis_after=False to allow the scrolling.

Real-time multi-line chart

Real-time multi-line chartReal-time multi-line chart
import lightningchart as lc
import time
import random

lc.set_license('my-license-key')

series_list = []
series_amount = 5

chart = lc.ChartXY(title='Real-time multi-line chart')
for i in range(series_amount):
# Create line series with ProgressiveX data pattern
series_list.append(chart.add_line_series(data_pattern='ProgressiveX'))

# Get the default x-axis reference
axis_x = chart.get_default_x_axis()
# Apply the progressive axis scroll strategy
axis_x.set_scroll_strategy('progressive')
# Set the axis interval and allow it to scroll
axis_x.set_interval(start=0, end=100000, stop_axis_after=False)

chart.open(live=True)

x = 0
y = []
for i in range(series_amount):
y.append(0)
for _ in range(1000): # Generate random real-time data
x += 1
for i in range(series_amount):
y[i] = y[i] + (random.random() * 2) - 1
series_list[i].add(x * 1000, y[i])
time.sleep(0.01)

chart.close()

Heatmap Scrolling Grid Series

Real-time heatmapReal-time heatmap

Both HeatmapGridSeries and SurfaceGridSeries have variations for Series with API for pushing data in a scrolling manner (append new data on top of existing data). These are HeatmapScrollingGridSeries and SurfaceScrollingGridSeries.

Upon creation, a resolution must be defined for Heatmap Scrolling Grid Series, i.e., the number of rows and columns. When working with a heatmap series, a color palette must be defined with heatmap_series.set_palette_colors() or heatmap_series.set_min_max_palette_colors() in order to distinguish the data intensity values visually. Data can be appended to the series with heatmap_series.add_intensity_values()

import lightningchart as lc
import random
import math
import time

lc.set_license('my-license-key')

chart = lc.ChartXY(title='Real-time heatmap')

# Configure scrolling axis
axis = chart.get_default_x_axis()
axis.set_scroll_strategy(strategy='progressive')
axis.set_interval(start=-50, end=0, stop_axis_after=False)

# Configure scrolling heatmap series
heatmap = chart.add_heatmap_scrolling_grid_series(
resolution=10000,
scroll_dimension='columns',
)
heatmap.set_start(0, 0)
heatmap.set_step(1, 1)
heatmap.hide_wireframe()
heatmap.enable_data_cleaning(True)

# Configure heatmap coloring
heatmap.set_palette_colors(
steps=[
{'value': 0, 'color': lc.Color(255, 192, 0)},
{'value': 100, 'color': lc.Color(255, 0, 0)},
],
look_up_property='value',
percentage_values=False
)

chart.open(live=True)

# Generate random real-time data
for i in range(500):
data = [[math.tan(i) * random.randint(0, 100) for j in range(10000)]]
heatmap.add_intensity_values(data) # Add values to the series
time.sleep(0.05)

chart.close()

Surface Scrolling Grid Series

Real-time 3D surfaceReal-time 3D surface

Surface Scrolling Grid Series functions similarly to Heatmap Scrolling Grid Series as in the way that you have to define a color palette and setup automatic scrolling strategy for the axis.

Data can be appended to the series with surface_series.add_values()

import lightningchart as lc
import random
import time

lc.set_license('my-license-key')

chart = lc.Chart3D(title='Scrolling 3D surface')

# Configure scrolling axis
axis = chart.get_default_x_axis()
axis.set_scroll_strategy(strategy='progressive')
axis.set_interval(start=-99, end=0, stop_axis_after=False)

# Configure scrolling surface series
surface = chart.add_surface_scrolling_grid_series(columns=100, rows=100)
surface.set_wireframe_stroke(1, color=lc.Color(0, 0, 0, 255))

# Configure surface coloring
surface.set_palette_colors(
steps=[
{'value': -10, 'color': lc.Color(0, 128, 255)},
{'value': 0, 'color': lc.Color(0, 255, 0)},
{'value': 10, 'color': lc.Color(255, 128, 0)},
],
look_up_property='y', # Datapoints are colored according to their y value
percentage_values=False
)

chart.open(live=True)

x = 0
for i in range(1000): # Generate random real-time data
x = x + (random.random() * 2) - 1
datagrid = [[x + random.uniform(0, 1) for j in range(100)]]
datagrid[0][0] = datagrid[0][-1] = x - 3
surface.add_values(datagrid) # Add values to the series
time.sleep(0.01)

chart.close()