Scatter plot with different text at each data point
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.
Introduction
Scatter plots are a fundamental visualization tool in data science and statistics, used to display and analyze the relationship between two numerical variables. Typically, each point on the scatter plot represents an observation from the dataset. In some cases, adding text annotations to each data point can provide additional insights, by labeling each point with relevant information such as an identifier or a specific value.
The Basics of Scatter Plots
A scatter plot consists of an x-axis and a y-axis, each representing one of the variables in the dataset. Data points are plotted in the coordinate space according to their values on these two axes.
To create a basic scatter plot, follow these steps:
- Select the Variables: Choose the two numerical variables you wish to analyze.
- Plot the Data Points: Each pair of values (x, y) from the dataset is plotted as a point on the graph.
- Analyze the Pattern: Look for any patterns, trends, or clusters.
Adding Text to Data Points
Annotating data points with text can add a layer of understanding to a scatter plot. This is especially useful when:
- Identifying Outliers: You can mark statistically significant outliers for further examination.
- Labeling Categories: If data points belong to different categories or classes, annotations can make these distinctions clearer.
- Highlighting Special Values: Points representing key metrics or critical values might be emphasized with labels.
Technical Explanation
Consider a dataset containing house prices and square footage:
| Square Footage | ||
| 1500 | 350 | A1 |
| 1800 | 420 | B2 |
| 1600 | 390 | C3 |
To create a scatter plot with text annotations:
- Plot the Points: First create a traditional scatter plot with the x-axis representing the square footage and the y-axis representing the price.
- Annotate Each Point: Use a plotting library such as Matplotlib in Python to add text. Here's an example:
- Enhanced Interpretability: Text annotations make a plot more informative, allowing for immediate identification of patterns.
- Customization: You can customize how you display information, using different fonts or colors to emphasize certain points.
- Clutter: Over-annotating a plot can make it cluttered and hard to decipher, especially with large datasets.
- Legibility: Ensure the text is easily readable, choosing appropriate sizes and avoid overlapping when possible.
Related reading
- Sci-kit learn how to print labels for confusion matrix?
- scikit-learn classification on soft labels
- Scikit-learn confusion matrix
- SciKit-Learn Label Encoder resulting in error 'argument must be a string or number
- Scikit-Learn Decision Tree Probability of prediction being a or b?
- Scikit learn - fit_transform on the test set
- Scikit-Learn Label not x is present in all training examples
- scikit-learn Predicting new points with DBSCAN

DSA Fundamentals
Master algorithmic patterns and data structures through hands-on LeetCode-style problems - from arrays and hashing to dynamic programming and advanced graphs.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
ML System Design practice on Codemia
Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.