Visualization, Exploratory Analytics and Decision SupportIntroductionData visualisation is the process of representing data graphically so that patterns, comparisons, trends, exceptions and uncertainty can be understood. Exploratory data analysis (EDA) combines visual methods, descriptive statistics and domain knowledge to investigate a dataset before formal modelling or decision-making. In Python, Matplotlib provides detailed control over figures, while Seaborn offers statistically oriented and aesthetically consistent visualisations built on Matplotlib. A chart is not merely an attractive presentation of data. It is an analytical argument. The choice of variables, scale, aggregation, colour and annotation influences what a reader notices and what conclusions appear reasonable. A responsible analyst therefore connects every visualisation to a question: What decision might this chart support? What evidence does it provide? What uncertainty or limitation must be disclosed? This chapter develops a practical workflow for using Python to summarise distributions and relationships, communicate uncertainty and produce managerial reports. Learning objectivesBy the end of this chapter, students should be able to: - distinguish exploratory, explanatory and decision-support visualisations;
- select suitable charts for categorical, numerical and time-based data;
- create and customise Matplotlib and Seaborn charts;
- summarise distributions using appropriate descriptive statistics;
- investigate relationships, association and possible outliers;
- communicate sampling uncertainty and avoid misleading graphical claims;
- build a reproducible exploratory-analysis workflow; and
- translate analytical findings into cautious, actionable managerial recommendations.
1. The role of visualisation in data scienceVisualisation serves three related purposes. Exploratory visualisation helps the analyst discover structure, anomalies and possible explanations. Explanatory visualisation communicates a selected finding to an audience. Decision-support visualisation connects evidence to an operational, financial or strategic choice. These purposes overlap but should not be confused. An exploratory scatter plot may contain many points, labels and diagnostic overlays. A management report may need a simpler chart showing the trend, the decision threshold and the relevant uncertainty. The same data can therefore require different visual designs at different stages. A useful visualisation has four properties: - Accuracy: graphical distances, positions and labels represent the data faithfully.
- Relevance: the chart addresses a defined analytical or business question.
- Clarity: the reader can identify the message without unnecessary effort.
- Integrity: the chart discloses important assumptions, exclusions and uncertainty.
A visualisation can be technically correct yet analytically weak. For example, a three-dimensional pie chart may display valid percentages, but perspective and area comparisons make accurate interpretation difficult. Similarly, a line chart joining unrelated categories can imply a trend that does not exist. 2. A reproducible Python workflowA practical workflow is: - define the decision or question;
- inspect the data structure and metadata;
- clean types, missing values and duplicates;
- describe individual variables;
- examine relationships between variables;
- investigate unusual observations and possible data errors;
- construct a small set of purposeful visualisations;
- document assumptions and limitations; and
- communicate findings with recommendations and next steps.
Typical imports are: import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
sns.set_theme(style="whitegrid", context="notebook") A dataset should be inspected before plotting: df.head()
df.shape
df.info()
df.describe(include="all")
df.isna().sum()
df.duplicated().sum() Dates should be converted explicitly, and numerical columns should not remain as text merely because they contain currency symbols or separators: df["date"] = pd.to_datetime(df["date"], errors="coerce")
df["sales"] = pd.to_numeric(df["sales"], errors="coerce") The use of errors="coerce" converts invalid values to missing values. This is useful for detection, but the resulting missing records must be investigated rather than silently discarded. 3. Choosing a chart for the analytical questionThe chart type should follow the structure of the question and the measurement level of the variables. | Analytical purpose | Suitable chart | Typical use |
|---|
| Distribution of one numerical variable | Histogram, density plot, box plot | Sales amounts, delivery time | | Comparison across categories | Bar chart, dot plot, box plot | Revenue by region | | Change over time | Line chart, area chart | Monthly demand | | Relationship between two numerical variables | Scatter plot, hexbin plot | Advertising spend and sales | | Relationship between categories | Grouped bar chart, heat map | Product and region counts | | Composition | Stacked bar chart, carefully used part-to-whole chart | Market share | | Geographic pattern | Map or spatial plot | Regional performance |
A bar chart is appropriate for comparing separate categories. A histogram is appropriate for numerical intervals. Replacing a histogram with a bar chart can incorrectly suggest that numerical bins are unrelated categories. Conversely, using a line between unordered categories can imply continuity. 3.1 Matplotlib fundamentalsMatplotlib provides figure and axes objects. The object-oriented style is preferred for reports because it supports multiple plots and precise control: fig, ax = plt.subplots(figsize=(8, 4.5))
ax.plot(monthly["month"], monthly["sales"], marker="o", linewidth=2)
ax.set_title("Monthly sales")
ax.set_xlabel("Month")
ax.set_ylabel("Sales (£)")
ax.tick_params(axis="x", rotation=45)
fig.tight_layout()
plt.show()The figsize values are measured in inches. Titles should describe the subject, while subtitles or annotations may explain the message. Axis labels must include units where relevant. A chart should not rely on colour alone; line styles, markers, labels or direct annotations improve accessibility. 3.2 Seaborn statistical graphicsSeaborn is particularly useful when a chart should show distributions or relationships by group: fig, ax = plt.subplots(figsize=(8, 5))
sns.scatterplot(
data=df, x="advertising_spend", y="sales",
hue="region", style="channel", alpha=0.75, ax=ax
)
ax.set_title("Sales and advertising spend by region and channel")
ax.set_xlabel("Advertising spend (£)")
ax.set_ylabel("Sales (£)")
fig.tight_layout()The alpha parameter controls transparency. It can reveal overlapping observations, but excessive transparency can make a chart appear faint. For large datasets, hexbin plots or sampled points may communicate density more effectively. 4. Summarising distributionsA distribution describes how values are positioned and how frequently they occur. Important features include centre, spread, shape and unusual observations. The arithmetic mean for observations x₁, x₂, …, xₙ is: x̄ = (1/n) ∑ᵢ₌₁ⁿ xᵢ Here, x̄ is the sample mean, xᵢ is observation i, and n is the number of non-missing observations. The mean is appropriate when values are quantitative and extreme observations do not dominate interpretation. The sample variance and sample standard deviation are: s² = [1/(n − 1)] ∑ᵢ₌₁ⁿ (xᵢ − x̄)²
s = √s² The denominator n − 1 is used when s² estimates the variance of a wider population from a sample. These measures use squared units and original units respectively. Standard deviation is not automatically a measure of uncertainty about the mean; it measures variation among observations. The median is the middle ordered value, and the interquartile range is: IQR = Q₃ − Q₁ where Q₁ is the 25th percentile and Q₃ is the 75th percentile. The median and IQR are often more robust than the mean and standard deviation for skewed data. Python can calculate these summaries directly: summary = df["delivery_days"].describe()
print(summary)
median = df["delivery_days"].median()
iqr = df["delivery_days"].quantile(0.75) - df["delivery_days"].quantile(0.25) A histogram reveals shape, but its appearance depends on bin width. Too few bins hide structure; too many bins create visual noise. A box plot compactly displays the median, quartiles and potential extreme values, but it does not show all aspects of a distribution. Use several complementary views when the decision warrants them. fig, axes = plt.subplots(1, 2, figsize=(11, 4))
sns.histplot(data=df, x="delivery_days", bins=20, kde=True, ax=axes[0])
sns.boxplot(data=df, x="delivery_days", ax=axes[1])
axes[0].set_title("Distribution of delivery time")
axes[1].set_title("Quartiles and potential extremes")
fig.tight_layout()A potential outlier is not necessarily an error. It may represent a genuine high-value customer, an unusual disruption or a different process. Analysts should investigate the record, its measurement process and its business meaning before removing it. 5. Examining relationshipsA scatter plot is useful for two numerical variables. It can reveal direction, form, clusters, changing variability and influential observations. Covariance measures joint variation, while Pearson correlation standardises covariance: r = [∑ᵢ₌₁ⁿ (xᵢ − x̄)(yᵢ − ȳ)] / √[∑ᵢ₌₁ⁿ(xᵢ − x̄)² × ∑ᵢ₌₁ⁿ(yᵢ − ȳ)²] Here xᵢ and yᵢ are paired observations, x̄ and ȳ are sample means, and r lies between −1 and 1 when both variables have non-zero variation. Pearson correlation measures linear association. It does not establish causation and can be misleading for curved relationships, outliers, restricted ranges or mixed subgroups. r = df[["advertising_spend", "sales"]].corr().loc["advertising_spend", "sales"]
print(f"Pearson correlation: {r:.2f}")Spearman correlation uses ranks and is useful for monotonic relationships that are not necessarily linear or when variables are ordinal. Neither coefficient replaces visual inspection. Grouped visualisation can expose aggregation problems: sns.lmplot(
data=df, x="advertising_spend", y="sales",
hue="region", height=5, aspect=1.3,
scatter_kws={"alpha": 0.6}
)A strong overall relationship may disappear within each region, or separate regional relationships may be combined into a misleading overall pattern. This is one reason analysts should examine important subgroups and consider confounding variables. 6. Time-series and categorical analysisTime-series charts require chronological ordering and consistent time intervals. Aggregation should be explicit: daily = (
df.set_index("date")
.resample("D")["sales"]
.sum()
.reset_index()
)
fig, ax = plt.subplots(figsize=(9, 4.5))
sns.lineplot(data=daily, x="date", y="sales", ax=ax)
ax.set_title("Daily sales")
ax.set_xlabel("Date")
ax.set_ylabel("Sales (£)")
fig.tight_layout()A moving average can reduce short-term noise, but it changes the quantity being displayed. For a window of w observations, a simple moving average at time t is: MAₜ = (1/w) ∑ⱼ₌₀w−1 xₜ₋ⱼ This assumes equally spaced observations and gives equal weight to the w most recent values. The choice of w should be stated because it affects apparent timing and smoothness. For categorical comparisons, order categories by a meaningful measure rather than by arbitrary alphabetical order: order = (df.groupby("region", as_index=False)["sales"]
.sum()
.sort_values("sales", ascending=False)["region"])
sns.barplot(data=df, x="region", y="sales", order=order, estimator="sum", errorbar=None)
plt.xticks(rotation=30)
plt.ylabel("Total sales (£)")
plt.title("Total sales by region")
plt.tight_layout()Bar charts should normally begin at zero when bar length encodes magnitude. Truncated axes can exaggerate differences, especially when bars are compared by their lengths. 7. Communicating uncertaintyA sample statistic is an estimate, not a perfectly known population value. Uncertainty may arise from sampling, measurement, missing data, model assumptions and future variation. For a sample mean, an approximate 95% confidence interval based on a t distribution is: x̄ ± t₀.₉₇₅, n−1 × s/√n Here x̄ is the sample mean, s is the sample standard deviation, n is the sample size, and t₀.₉₇₅, n−1 is the 97.5th percentile of the t distribution with n − 1 degrees of freedom. This interval is appropriate when observations are reasonably independent and the sampling design supports the inference; for small samples, the population distribution should not be severely non-normal. A 95% confidence interval is not correctly interpreted as a 95% probability that this already calculated interval contains the fixed population mean. In repeated sampling under the stated procedure, approximately 95% of constructed intervals would contain the parameter. Seaborn can display confidence intervals for an estimated mean, although the exact method and version-dependent defaults should be checked: sns.pointplot(
data=df, x="region", y="sales",
errorbar=("ci", 95), capsize=.1
)Uncertainty bands should not be confused with prediction intervals. A confidence interval for a mean describes uncertainty in an estimated average; a prediction interval concerns the likely range for an individual future observation and is usually wider. Charts should state what error bars represent: standard deviation, standard error, confidence interval or another quantity. Ambiguous error bars invite incorrect conclusions. 8. From EDA to managerial decision supportDecision support requires a chain of reasoning: Question → Measure → Evidence → Uncertainty → Action → Monitoring For example, a manager may ask whether delivery performance has deteriorated. The analyst must define performance, choose an appropriate time period, distinguish average delay from the proportion exceeding a service-level target, examine regions or carriers, quantify uncertainty and recommend an intervention. A single average may conceal a serious problem affecting a small but important customer group. A decision-support report should normally include: - the decision context and audience;
- data source, period, grain and exclusions;
- definitions of measures and targets;
- two or three charts with direct titles;
- the principal finding and its uncertainty;
- alternative explanations and limitations;
- a recommended action, owner and time frame; and
- a monitoring measure for evaluating the action.
The report should separate facts, interpretations and recommendations. “Region A had the highest average delay” is a descriptive claim. “Carrier capacity may be contributing to the delay” is a hypothesis. “Pilot an additional carrier for four weeks” is a recommendation. These statements require different levels of evidence. Illustrative case: reducing late deliveriesBackground. A fictional online retailer records order date, promised date, delivery date, region, carrier and order value. Managers suspect that late deliveries are damaging repeat purchases. Problem. The company needs to decide whether to renegotiate carrier service levels, redistribute volume or change promised delivery dates. Analysis. The analyst first defines lateness as actual delivery date later than promised delivery date. A binary indicator is created: df["late"] = (df["delivered_date"] > df["promised_date"]).astype(int) The analyst checks missing dates, impossible negative delivery durations and duplicate order identifiers. A time-series plot shows weekly late-order rates. Box plots compare delivery days by carrier, while a grouped bar chart compares late rates by region and carrier. The analyst also reports sample sizes because a high rate based on very few orders is less stable than a similar rate based on thousands of orders. Approach and solution. Results indicate that one carrier has a higher late rate in the northern region, but the carrier handles a greater proportion of remote destinations. The analyst therefore avoids concluding that the carrier alone causes lateness. A controlled four-week pilot assigns comparable northern routes to an alternative carrier where operationally feasible. The report recommends tracking late rate, average delay, customer complaints and cost per delivered order. Outcome. In this illustrative scenario, the pilot reduces late deliveries but increases delivery cost. Management chooses the alternative carrier only for high-value or service-sensitive orders and retains the original carrier for low-risk routes. Learning points. The case demonstrates the importance of definitions, subgroup analysis, exposure volume, confounding factors, cost trade-offs and post-intervention monitoring. Visualisation supports the decision but does not replace operational experimentation or managerial judgement. 9. Visual integrity, ethics and governanceData visualisations can cause harm when they conceal relevant information or encourage unjustified decisions. Important safeguards include: - disclose missing-data treatment and exclusions;
- avoid cherry-picking time periods or subgroups;
- preserve meaningful zero points when appropriate;
- use consistent scales when comparing panels;
- distinguish counts from rates and percentages;
- report denominators for proportions;
- avoid implying causation from observational association;
- protect personally identifiable and sensitive information; and
- document code, data versions and transformations.
Privacy requires particular care with dashboards containing small groups, locations or rare events. Aggregation, suppression or controlled access may be necessary. Fairness should also be considered: a visualisation that ranks branches, employees or customers may reproduce biases in the underlying data or measurement process. Accessibility is part of professional quality. Use readable font sizes, sufficient contrast, descriptive labels and colour palettes suitable for colour-vision deficiencies. Do not encode the only distinction through red and green. Provide a textual interpretation for charts distributed to audiences using assistive technologies. 10. Reproducibility and contemporary practiceA professional analysis should be reproducible. Store data-cleaning steps in scripts or notebooks, use explicit package versions where possible, separate raw and processed data, and record the date and source of extraction. Random sampling should use a documented seed when reproducibility is required: sample = df.sample(n=500, random_state=42) Interactive dashboards can support filtering and monitoring, but interactivity should not hide definitions or make the result impossible to audit. Automated and AI-assisted chart generation can accelerate exploration, yet analysts remain responsible for checking aggregation, axis scales, statistical assumptions, privacy and interpretation. Generated explanations should be treated as drafts requiring domain validation. Best-practice checklistBefore publishing a chart or report, ask: - What question does the visualisation answer?
- Are the variables and units clearly defined?
- Is the chart type appropriate for the data structure?
- Are the axis scales, categories and time order honest?
- Are missing values, denominators and exclusions documented?
- Does the chart show uncertainty where it matters?
- Have important subgroups and alternative explanations been examined?
- Can a reader identify the recommended action and its risks?
- Is the analysis reproducible and accessible?
- Does the evidence justify the strength of the conclusion?
Chapter SummaryVisualisation is an analytical and communication discipline, not simply a formatting task. Matplotlib supports precise figure construction, while Seaborn provides convenient statistical graphics. Effective exploratory analysis begins with data inspection and proceeds through distributional summaries, relationship analysis, subgroup comparisons and investigation of anomalies. Means and standard deviations are useful under suitable conditions, while medians and interquartile ranges are often more robust for skewed data. Correlation describes association, not causation. Time-series charts require chronological ordering and explicit aggregation. Bar charts compare categories, histograms display numerical distributions, scatter plots examine relationships and box plots summarise grouped distributions. Confidence intervals and clearly labelled error bars help communicate uncertainty, but their interpretation depends on sampling assumptions. Decision-support reports connect a defined question to evidence, limitations, action and monitoring. Ethical practice requires honest scales, transparent definitions, privacy protection, accessibility and reproducibility. Key TermsExploratory data analysis: Investigation of data using summaries, visualisations and domain knowledge before formal modelling. Explanatory visualisation: A visualisation designed to communicate a selected finding clearly. Decision-support visualisation: A chart or dashboard intended to inform a specific managerial or operational decision. Distribution: The pattern of values and frequencies for a variable. Mean: The arithmetic average of numerical observations. Median: The middle ordered observation, or the midpoint of the two middle observations when the count is even. Standard deviation: A measure of spread in the original units of a numerical variable. Interquartile range: The difference between the 75th and 25th percentiles. Outlier: An observation unusually distant from the general pattern; it may be genuine or erroneous. Correlation: A numerical measure of association between variables, commonly focused on linear association. Confounding: A situation in which another variable helps explain an observed association. Aggregation: Combining observations into summaries such as totals, averages or rates. Confidence interval: An interval produced by a procedure intended to capture a population parameter at a stated long-run coverage level. Prediction interval: An interval describing uncertainty about a future individual observation. Histogram: A chart showing frequencies or densities across numerical bins. Box plot: A chart showing quartiles, median and potential extreme observations. Scatter plot: A chart displaying paired values for two numerical variables. Data provenance: Documentation of a dataset’s source, transformations and history. Reproducibility: The ability to repeat an analysis and obtain consistent results using the documented data and code. Dashboard: A collection of coordinated visualisations used for monitoring or decision support. Review QuestionsShort Answer Questions- Distinguish exploratory visualisation from explanatory visualisation.
- Why is a histogram generally more suitable than a bar chart for delivery times?
- Define the interquartile range and state why it can be useful for skewed data.
- Why does correlation not establish causation?
- Name two items that should be documented when presenting an error bar.
Long Answer Questions- Explain how you would conduct a reproducible EDA of a sales dataset, from initial inspection to managerial reporting.
- Compare histograms, box plots and density plots as tools for understanding a numerical distribution.
- Explain the assumptions and interpretation of a 95% confidence interval for a sample mean.
- Discuss how aggregation and subgroup analysis can change the interpretation of a relationship between two variables.
- Develop a set of visualisation and accessibility standards for a professional management dashboard.
Analytical / Application Questions- A manager observes a strong positive correlation between advertising expenditure and sales. Propose an EDA plan that tests whether the relationship may be confounded by region, season or company size.
- A carrier’s late-delivery rate is 12% for 50 orders, while another carrier’s rate is 10% for 5,000 orders. Explain why rates alone are insufficient for the decision and identify additional evidence required.
- Design a decision-support report for a retailer considering a new delivery provider. Specify the measures, charts, uncertainty information, ethical safeguards and monitoring plan you would include.
Multiple Choice Questions with AnswersQuestion 1Which chart is most appropriate for examining the distribution of a single numerical variable such as delivery time? A. Histogram B. Pie chart C. Network diagram D. Grouped categorical table Correct Answer: A. Histogram Question 2What does the interquartile range measure? A. The difference between the maximum and minimum values B. The difference between the 75th and 25th percentiles C. The arithmetic average of all values D. The proportion of missing values Correct Answer: B. The difference between the 75th and 25th percentiles Question 3Which statement about Pearson correlation is correct? A. It proves that one variable causes another B. It measures only the number of missing observations C. It measures the strength and direction of linear association D. It is always appropriate for categorical variables Correct Answer: C. It measures the strength and direction of linear association Question 4Why should a bar chart comparing magnitudes normally begin at zero? A. To make the chart use more colours B. To preserve a truthful visual comparison of bar lengths C. To remove all uncertainty from the data D. To guarantee that categories are independent Correct Answer: B. To preserve a truthful visual comparison of bar lengths Question 5In the sample standard deviation formula, why is n − 1 commonly used in the denominator? A. To estimate population variance from a sample with less biased variance estimation B. To convert numerical data into categorical data C. To ensure the standard deviation is always zero D. To calculate a confidence level of exactly 100% Correct Answer: A. To estimate population variance from a sample with less biased variance estimation Question 6Which statement correctly distinguishes a confidence interval from a prediction interval? A. A prediction interval concerns an individual future observation and is often wider B. A confidence interval always contains every future observation C. A prediction interval is used only for categorical variables D. There is no conceptual difference between them Correct Answer: A. A prediction interval concerns an individual future observation and is often wider Question 7Which Python library is built specifically on Matplotlib and provides convenient statistical graphics? A. Seaborn B. NumPy C. Requests D. SQLite Correct Answer: A. Seaborn Question 8What is a major danger of interpreting an overall correlation without subgroup analysis? A. The chart will necessarily contain too few colours B. Relationships may differ across groups or be affected by confounding C. The data will automatically become normally distributed D. The sample size will become infinite Correct Answer: B. Relationships may differ across groups or be affected by confounding Question 9Which practice best supports reproducibility? A. Changing data-cleaning steps manually without recording them B. Using undocumented chart defaults C. Recording transformations, data sources and analysis code D. Removing all unusual observations without explanation Correct Answer: C. Recording transformations, data sources and analysis code Question 10What should a professional report do when showing error bars? A. Leave their meaning unexplained B. State whether they represent standard deviation, standard error or a confidence interval C. Use them only when the sample size is one D. Treat them as proof of causation Correct Answer: B. State whether they represent standard deviation, standard error or a confidence interval
|