Editor

Detect Misleading Chart Configurations

Advanced · Write the code · from Data Visualization: Choose the Right Chart and Tell a Story

From the lesson: Data Visualization: Choose the Right Chart and Tell a Story

A chart that looks pretty but tells the wrong story is worse than no chart at all. In 1986, NASA engineers showed managers a chart arguing that cold temperatures could damage the Space Shuttle Challenger's O-ring seals. The chart was so poorly designed that the managers couldn't see the pattern.

Read the lesson

Write a function find_issues(config) that takes a dictionary with chart configuration and returns a list of issue strings. Check for these problems: (1) If y_min is not 0 and chart_type is 'bar', add 'truncated axis'. (2) If categories > 6 and chart_type is 'pie', add 'too many pie slices'. (3) If is_3d is True, add 'unnecessary 3d'. (4) If has_title is False, add 'missing title'. Print the sorted issues for the test config.

def find_issues(config):
issues = []
# Check for problems
return sorted(issues)
# Test with a problematic chart
test_config = {
'chart_type': 'pie',
'categories': 10,
'y_min': 50,
'is_3d': True,
'has_title': False,
}
result = find_issues(test_config)
for issue in result:
print(issue)

More Data Visualization exercises

All Python exercises · 50 practice problems · Data Science & Machine Learning quiz