PyNarrative: A Python Library for Data Storytelling

angelicaloduca 353 views 21 slides Mar 25, 2025
Slide 1
Slide 1 of 21
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21

About This Presentation

PyNarrative is a Python library for data storytelling.

More details here:
https://github.com/pynarrative/pynarrative

Install PyNarrative as follows:
pip install pynarrative


Slide Content

PyNarrative: A Python Library
for Data Storytelling

Angelica Lo Duca, Roberto Olinto Barsotti

Introduction
PyNarrative is a Python library we created and developed to facilitate data
narration.
The central theme of the work is the integration of technology and
communication through data storytelling.

There is a big gap between developers
and the communication of data, as
they often lack the necessary skills to
convey them clearly and effectively

The current survey of data visualisation libraries
includes:
State of the Art
for Python:
•Matplotlib: specializing in static and interactive graphs
•Seaborn: focused on statistical graphs
•Plotly: oriented towards web views
•Altair: characterised by a declarative approach

For other languages:
State of the Art
•D3.js for JavaScript
•ggplot2 for R
•JFreeChart for Java
However, these libraries focus mainly on
visualisation, neglecting the narrative aspect.

Data scientists face different challenges:

The Problem
•Existing tools, although powerful, are complex
to use
•Dozens of lines of code are needed to
implement narrative elements
•Different applications are necessary
•Communication with a non-technical audience
is difficult

To create a simple story using Altair requires
more than 100 lines of code , resulting in a
time-consuming technical set-up rather than
storytelling.

WHAT IS PYNARRATIVE?
PyNarrative is a library designed to integrate narrative
elements seamlessly into data visualization.

Instead of writing too many lines of code to add explanations,
annotations, and context, PyNarrative simplifies this process
with structured storytelling components.

PyNarrative was created with the aim of bridging the gap
between visualisation and data narration. Key features include:
Introduction to PyNarrative
•Integration with Altair as a technology base

•A structured narrative approach
•Significant reduction in code complexity

KEY INNOVATIONS:
●First library to natively implement full narrative structure
●Smooth and natural integration of all narrative elements
●Support for different cultures and reading styles

class Story:
def add_context(text, position, color)
def add_annotation(text, position, color)
def add_next_steps(text, position, mode)
def add_source(text, position)
def add_title(title, subtitle)
def add_line(value, orientation)
def configure_view(**kwargs)
def render():

Story composition in 3 acts
The three fundamental parts of every story (Aristotle, 335 BC):
●MIDDLE: The core of the narrative
○The main visual representation with integrated annotations
○Supported by functions like add_annotation() and
add_source()

●END: Conclusions and future actions
○Guides the audience towards insights and next steps
○Implemented using add_next_steps(), offering various
interaction modes

●BEGINNING: Context and background
○Helps set the stage by providing relevant background
information
○Implemented using the add_context() function

Context
Context
Next Steps
Next Steps
Annotation
Credits
Credits
Credits
Credits

The empirical comparison between PyNarrative
and the traditional approach shows:
Results and Benefits
PyNarrative Traditional approach
Development time 10-15 minutes 70-100+ minutes
Code lines less than 20 beyond 100

Impact and Future

Future prospects may include:
Future Developments
Integration with AI:
•Automated context generation
•Image creation
•Annotation tips
•Layout optimization
Expansion of
functionalities:
•New display types
•Advanced narrative templates
•Support for complex datasets

The project achieved important goals:
Conclusions
•Significant reduction in complexity
•Improved data communication
•Effective narrative support

Repository Links:
https://github.com/pynarrativ
e/pynarrative?tab=readme-o
v-file
https://pynarrative.github.io/doc/p
ynarrative.html
Api documentation:

https://pypi.org/project
/pynarrative/

> pip install pynarrative

Thank you for
your attention