Choose the Right Chart Type
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 lessonWrite a function choose_chart(data_description) that takes a string describing the data and returns the best chart type. Handle these cases: if the description contains "over time" or "trend", return 'line'. If it contains "compare" or "categories", return 'bar'. If it contains "relationship" or "correlation", return 'scatter'. If it contains "distribution", return 'histogram'. If it contains "proportion" or "percentage", return 'bar' (not pie -- bar is almost always better). Otherwise return 'bar' as the safe default. Test with the provided descriptions.
More Data Visualization exercises
All Python exercises · 50 practice problems · Data Science & Machine Learning quiz