Choosing the Right Chart for Your Data
After completing this topic:
You will be able to determine the appropriate chart type based on what your data is trying to convey.
Ask yourself first:
Before choosing a chart, first determine "what you want to show with this data." Even the same data can be represented with different charts depending on the purpose.
| What you want to show | Chart type |
|---|---|
| Size comparison | Bar chart |
| Change over time | Line chart |
| Distribution (how spread out) | Histogram, box plot |
| Relationship between two variables | Scatter plot |
| Proportion relative to the whole | Pie chart, stacked bar chart |
1. Comparison - Bar Chart
Most effective for comparing sizes between categories, such as "sales by department" or "population by country."
sns.barplot(data=df, x='department', y='revenue')Rules:
- If there are many items, a horizontal bar chart is easier to read.
- It must start at 0 β starting at 100 exaggerates the differences.
- The order of items is generally sorted by value (not alphabetically).
2. Trend - Line Chart
Shows changes over time, such as "monthly sales" or "daily visitors."
sns.lineplot(data=df, x='month', y='revenue')Rules:
- The x-axis is time β if a category is on the x-axis, it's a bar chart, not a line chart.
- When overlapping multiple lines, keep it to 3 or fewer β more than that becomes a "spaghetti" chart.
- An area chart can show both the overall trend and changes relative to the whole.
3. Distribution - Histogram, Box Plot
Used to understand "how salaries are distributed" or "whether there are outliers."
# Histogram β frequency distributionsns.histplot(data=df, x='salary', bins=20)
# Box plot β median, quartiles, outlierssns.boxplot(data=df, x='department', y='salary')| Histogram | Box plot | |
|---|---|---|
| Shows | Overall distribution shape | Summary statistics (median/quartiles/outliers) |
| Strengths | Shows the number of peaks and whether it is skewed | Good for comparing groups and identifying outliers |
| Weaknesses | Difficult to compare groups | Does not show detailed distribution shape |
4. Relationship - Scatter Plot
Examines the relationship between two numerical variables, such as "does salary increase with experience?"
sns.scatterplot(data=df, x='experience', y='salary', hue='department')If the points form a linear pattern, there is a correlation; if they are scattered, there is no correlation. This was discussed in detail in the previous topic (heatmap and scatter plot).
5. Composition - Pie Chart (Use with caution)
Shows "the proportion of each part relative to the whole."
plt.pie(sizes, labels=labels, autopct='%1.1f%%')Reasons to avoid pie charts:
- It is difficult to distinguish between similar-sized slices β it is difficult to perceive the difference between 28% and 32% in terms of the angle of the pie slice.
- It becomes almost unreadable if there are more than 5 items.
Alternative: A horizontal stacked bar chart is more effective for comparing proportions. Comparing lengths is more in line with human cognitive abilities than comparing angles.
Chart Selection Flowchart
What do you want to show with the data?
β
ββ Size comparison βββββββββ Bar chart
β
ββ Change over time βββββββββ Line chart
β
ββ Distribution/outliers βββββββ Histogram or box plot
β
ββ Relationship between two variables ββββββ Scatter plot
β
ββ Correlation between multiple variables ββββ Heatmap
β
ββ Proportion relative to the whole ββββ Stacked bar chart (avoid pie charts)Common problems with bad visualizations
- 3D charts β perspective distorts size.
- Dual Y-axis β two scales create false correlations.
- Y-axis does not start at 0 β small differences appear large.
- Excessive use of colors β rainbow colors are flashy but distracting.
- No labels β charts without axis names, units, or titles are unreadable.
A good visualization allows you to understand "what this data is saying" within 5 seconds.
Key takeaway
Don't choose a chart first β decide "what you want to show" first. Use bar charts for comparisons, line charts for trends, histograms/box plots for distributions, scatter plots for relationships, and stacked bar charts for overall proportions. Avoid pie charts, and avoid 3D and dual Y-axes β simple and honest charts are good charts.