Tickmark algorithm for a graph axis
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
When displaying data graphically, it's imperative to have a clear and interpretable axis. An axis that fails to accurately represent the data can lead to misinterpretation. The Tickmark algorithm is one method used to determine optimal locations for tick marks on a graph's axis, ensuring clarity and enhancing interpretability.
Understanding Tickmarks
Tickmarks serve as reference points on graph axes to help viewers gauge the values of data points accurately. Proper tick mark placement can drastically affect the readability and viewer comprehension of a graph. The primary objective of a Tickmark algorithm is to generate tick marks that are both intelligent and aesthetically pleasing.
The Tickmark Algorithm
The Tickmark algorithm is designed to solve the problem of spacing tick marks on an axis effectively. It considers aesthetic criteria such as even spacing, coverage of the axis, and human-friendly numbers. This algorithm takes into account:
- Range of Data: Determines the minimum and maximum values of the dataset that needs to be displayed.
- Interval Calculation: Computes an interval that is a power of ten multiplied by 1, 2, or 5 (considered 'nice' numbers as they are easy to multiply and divide).
- Optimal Fit: Chooses tick marks that cover the entire range of data points while maintaining the balance between too many and too few tick marks.
Steps of the Algorithm
- Determine the Data Range: Compute the data's minimum (
min) and maximum (max) values. - Calculate an Initial Interval: • Compute the approximate range required by the axis:
Range = max - min. • Estimate an initial interval using the formula: - Adjust Interval Using Nice Numbers: • The initial interval is adjusted by multiplying it with values such as 1, 2, or 5 until an optimal number of tick marks is produced. This is computed as: • Select the multiplier such that the resulting number of ticks (
n) is aesthetic and practical, usually between 5 and 10. Formally: - Determine Tickmark Positions: • Starting from a value less than
minthat is a multiple ofInterval, incrementally addIntervalto generate tick marks until a value exceedingmaxis achieved.
Example
Consider a dataset with a minimum value of 12 and a maximum value of 158:
- Data Range Calculation: •
- Initial Interval: • Estimate:
- Adjust Interval Using Nice Numbers: • Evaluating with "nice numbers": multiply 100 by 1, 2, and 5 to check for suitable intervals. • If multiplied by 1, Interval = 100 (not suitable as it results in fewer than 5 ticks), • If multiplied by 2, Interval = 200 (too sparse), • If multiplied by 0.5, Interval = 50 (results in 3 tickmarks).
- Ideal Interval and Tickmarks: • Choose Interval as 25: this results in 6 tick marks which is optimal. • Tick positions: Start at 0, then 25, 50, 75, 100, 125, 150, and 175.
Key Points Summary
| Aspect | Description |
| Data Range | Minimum and maximum of the dataset |
| Initial Interval | Power of ten approximation of the range |
| Adjustment Factor | Nice numbers: 1, 2, 5 |
| Optimal Interval | Interval producing 5 to 10 tickmarks |
| Tick Positions | Multiple of interval from calculated start |
| Ideal Number of Ticks | Between 5 and 10 tickmarks recommended |
Considerations and Enhancements
• Logarithmic Scales: When data spans many orders of magnitude, logarithmic axis might be more suitable. • Precision Handling: Decimal intervals can be used for finer control over tick placement. • Dynamic Adjustment: Based on user interactions, dynamically adjust the tick interval for zoomed versions of graphs.
Conclusion
The Tickmark algorithm ensures that tick marks on a graph are not just precise but also well-spaced for human comprehension. By balancing the need for accuracy and aesthetics, this algorithm plays a crucial role in data visualization, positively influencing data readability and viewer understanding.
Related reading
- tight_layout doesn't take into account figure suptitle
- Time Series Analysis - unevenly spaced measures - pandas statsmodels
- Time Series Analysis Forecasting of categorical variables
- time series forecasting using R CARET package
- Tie breaking in a priority queue using python
- Time complexity analysis for finding the maximum element
- Time complexity deleting element of deque
- Time complexity for Dijkstra's algorithm with min heap and optimizations

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.