liveBook · Manning

Python

As explained in Data Storytelling with Altair and AI

Python is a general-purpose, high-level programming language widely used for data analysis and scientific computing.

Python is a general-purpose, high-level language used here to analyze data, create visualizations, and carry a data science project from experimentation through reporting. section 1.2 section 1.2.1

Python supports practical data storytelling in two complementary ways:

  • Use imperative libraries such as Matplotlib and Seaborn by specifying visualization steps, including axes, labels, titles, and styling. section 1.2
  • Use declarative Altair by describing the data, variables, chart type, and desired result while the library handles much of the construction. section 1.2
  • Keep analysis and reporting in Python instead of repeatedly exporting data to Tableau or Power BI during project revisions. section 1.2.1

Plotting square numbers

A line chart for x values 1 through 5 and y values 1, 4, 9, 16, and 25 can be built imperatively with Matplotlib or declaratively with Altair. The Matplotlib version specifies plot, title, axis labels, and display; the Altair version places the same data in a pandas DataFrame, encodes x and y, selects mark_line, and saves the chart. section 1.2

Listing 1.1 Imperative library
import matplotlib.pyplot as plt

x = [1, 2, 3, 4, 5]
y = [1, 4, 9, 16, 25]

plt.plot(x, y)
plt.title('Square Numbers')
plt.xlabel('X')
plt.ylabel('Y')

plt.show()

Inspect the step-by-step Matplotlib implementation of the square-numbers line chart. section 1.2

Listing 1.2 Declarative library
import altair as alt
import pandas as pd

df = pd.DataFrame({'x': [1, 2, 3, 4, 5], 'y': [1, 4, 9, 16, 25]})

chart = alt.Chart(df).mark_line().encode(
    x='x',
    y='y'
).properties(
    title='Square Numbers'
)

chart.save('chart.png')

Inspect the concise Altair implementation using a DataFrame, encodings, a line mark, and a chart title. section 1.2

How Data Storytelling with Altair and AI covers it

How deep it goes
Explains Python through visualization workflows and reporting integration, stopping short of general language internals or syntax instruction.
Examples
Demonstrates square-number line charts through contrasting Matplotlib and Altair implementations.
What you can do after
Apply Python to build visualizations and reports without repeatedly transferring analyzed data into external tools.
How it connects
Connects Python with Altair, Matplotlib, Seaborn, pandas, data visualization, generative AI, Tableau, and Power BI.

Also explained in

Compare how 26 books explain Python →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Data Storytelling with Altair and AI. The section links point to the parts of the book it draws on.