An essay with a heartbeat · first published August 2024, rebuilt October 2026

My heart beats like a network

How a 53-minute run, one heart-rate reading at a time, becomes a graph. An introduction to visibility graphs, with my own heart as the example.

A heart drawn as a network of points and lines

I have always been a romantic, probably due to the amount and genre of songs I was exposed to in my childhood. The first song I remember is from an Italian songwriter who sings about how everything he did reminded him of a special someone. Even as a child, I could sense a hint of the emotional struggle in his lyrics, though my young heart had yet to experience the full spectrum of joy and sorrow that comes with love, which governs our heartbeats.

But this essay isn't about romance or love; it's about heartbeats, and specifically how we can visualise and understand them with data science. My passion for complex systems and the way they behave has always driven me, as a person and as a data scientist. During my master's I became particularly interested in measuring and quantifying complex systems, extracting any relevant structure from what might at first look like a chaotic mess.

The approach here is one of my favourite ways to do that: the visibility graph. I will introduce how visibility graphs work, their mathematical side, and an artistic way to look at a heartbeat with them.

Understanding visibility graphs through skyscrapers

A visibility graph represents relationships between data points. To make it tangible, picture a city of skyscrapers. Each skyscraper is a data point, and its height is the value of that point. This city is quite particular: all the skyscrapers stand in a line along a single street, just like the points of a time series.

A street of skyscrapers of different heights

Now imagine you are standing on the roof of one of these skyscrapers. From there you can see some buildings down the line, while others are hidden by taller ones in between.

The concept of visibility

In our metaphor, visibility means you can see the roof of one skyscraper from the roof of another. For two skyscrapers to see each other there must be no building in between that is as tall or taller than the line of sight. If skyscraper A is 50 metres tall and B, further down the street, is 100 metres, A can see B unless something in between rises above the line joining their roofs. Put a 120-metre tower C between them, and A can no longer see B.

Stick figures on rooftops: one can see over a short building but not over a tall one
Made with Excalidraw, strongly suggested by Christian te Riet, Excalidraw's evangelist.

That is all we need to build a network. Each skyscraper becomes a node, and an edge joins two nodes whenever their roofs can see each other. Try it: drag the roofs up and down, or click a building to see what it can see.

The maths behind it

Non-metaphorically, a visibility graph turns a time series into a network: each data point is a node, and two nodes are linked when they have a clear line of sight. Quoting the original paper [1]:

Given a time series, two data values (ta, ya) and (tb, yb) are connected if any other value (tc, yc) between them fulfils $$y_c < y_b + (y_a - y_b)\,\frac{t_b - t_c}{t_b - t_a}$$

By construction, the graph is always:

  1. Connected: each node sees at least its nearest neighbours, left and right.
  2. Undirected: the algorithm defines no direction for the links.
  3. Invariant under affine transformations: rescaling or shifting either axis doesn't change who sees whom.

The straightforward algorithm takes $O(N^2)$ time for $N$ points; faster methods, such as the horizontal visibility graph, bring that down to $O(N \log N)$ [2, 3].

Why bother?

Visibility graphs capture both local and global properties of a series. The degree of a node describes its immediate neighbourhood; the average path length and the clustering coefficient describe the structure as a whole [4]. For fractal time series, the degree distribution follows a power law, $P(k) \sim k^{-\gamma}$, which has been used to characterise the complexity and self-similarity of a series [5].

They have found uses well beyond the textbook: in finance, to study market dynamics and exchange rates [6]; in neuroscience, to turn EEG or fMRI signals into networks and characterise how brain regions connect and synchronise [7].

You make my heart beat

Now we know how visibility graphs work. I hope I didn't lose too many of you in the serious part, but it makes the next bit easier to appreciate. When I had some time, I used to go for a run around the neighbourhood and record it with my sports watch. Among everything it records, there is the heartbeat.

The heartbeat time series becomes a graph, an object I studied for many years of my life.

Ever since I first heard about visibility graphs, I wanted to analyse something unseen and see what it would actually look like. The heartbeat was one of those things, but during my PhD I had neither a good smartwatch nor a proper way to measure it. Below is one of my runs: 691 readings over 53 minutes. Press play and watch the graph fill up as the run goes on. The heart in the corner beats at the rate of the moment being replayed.

ECG · paced from the real reading
Heart rate
—BPM
minute 0:00 of 53:24
83168 bpm
Hover a node to see its moment in the run. Drag the strip below to scrub.

Added in 2026 · what the graph says

Peaks become hubs

A reading sees far when it stands taller than its neighbours. So the hardest moments of the run turn into the graph's hubs: The flat, steady stretches only see the readings next to them, and they knit into tight local clusters.

That is why the network breaks so cleanly into communities: each one is a stretch of the run with its own rhythm. Switch the colour to Communities and they line up along the strip almost in order of time.

The degree distribution has a heavy tail. Most readings see a handful of others, a few see more than fifty. On log-log axes the tail falls roughly on a line with slope , the kind of scale-free signature visibility graphs pick up from fractal-like series.

How many readings each reading can see (degree k), log-binned. Dashed: least-squares power-law fit on the binned tail.

Conclusions

There is not much deep meaning in this piece of analysis. I made it to introduce a concept I love, the visibility graph, to a wider audience, and to combine it with something out of the ordinary, a heartbeat, into something almost artistic.

As a final note, I played around with the layout of the network and found a small surprise. Keep scrolling and watch my heartbeat graph…

…was hiding a heart.
  1. Lacasa, Luque, Ballesteros, Luque & Nuño (2008). From time series to complex networks: the visibility graph. PNAS 105(13), 4972–4975.
  2. Luque, Lacasa, Ballesteros & Luque (2009). Horizontal visibility graphs: exact results for random time series. Physical Review E 80(4), 046103.
  3. Lan, Mo, Chen, Liu & Deng (2015). Fast transformation from time series to visibility graphs. Chaos 25(8), 083105.
  4. Ahmadlou, Adeli & Adeli (2010). New diagnostic EEG markers of the Alzheimer's disease using visibility graph. Journal of Neural Transmission 117(9), 1099–1109.
  5. Lacasa & Toral (2010). Description of stochastic and chaotic series using visibility graphs. Physical Review E 82(3), 036120.
  6. Yang, Wang, Yang & Mang (2009). Visibility graph approach to exchange rate series. Physica A 388(20), 4431–4437.
  7. Ahmadlou, Ahmadi, Rezazade & Azad-Marzabadi (2013). Global organization of functional brain connectivity in methamphetamine abusers. Clinical Neurophysiology 124(6), 1122–1131.

Data: one Garmin TCX export, heart rate only (GPS removed). Visibility follows Lacasa et al., PNAS 2008, using real elapsed seconds as the x axis (the watch samples every ~4.6 s, unevenly). Communities: Louvain, seed 7. Layouts: each community laid out as its own lobe, and a heart where the readings run around the outline in time order.

Comments

Sign in with GitHub to leave a comment or react.

← Portfolio