Can this bar plot be shown as a pie chart with percentages? How can you show gender…
- User
Can this bar plot be shown as a pie chart with percentages? How can you show gender differences?
- Assistant
Short answer
You can turn it into a pie chart with percentages, but with ~20 topics it will be hard to read and won’t highlight gender gaps well.
To show gender differences, use one of these instead:
100% stacked bars (per topic) – shows, for each topic, what % is F vs M.
Normalized side‑by‑side bars – heights are percentages instead of raw counts.
Difference/ratio plot – bar (or dot) of (F%−M%) or log2(F/M) per topic, sorted.
Mosaic/Marimekko – area encodes both total volume and gender share.
Small-multiple pies (one per gender) – if you really want pies; still less comparable.
Why a single pie isn’t great One pie would only show overall topic proportions (summing both genders). Two pies (F vs M) add gender, but humans compare lengths more accurately than angles, so bars are clearer.
How to do it (Python / pandas + matplotlib) Assume you have a dataframe df with columns: topic, gender (values F/M), and one row per segment. pythonCopyEditimport pandas as pd import matplotlib.pyplot as plt
counts per topic x gender
counts = df.groupby(['topic','gender']).size().unstack(fill_value=0)
1) 100% stacked bars: within-topic percentages of F vs M
pct_within_topic = counts.div(counts.sum(axis=1), axis=0) * 100 ax = pct_within_topic.plot(kind='bar', stacked=True) ax.set_ylabel('% within topic') ax.set_xlabel('Topic ID') ax.legend(title='Gender') plt.tight_layout()
2) Normalized side-by-side bars: within-gender topic mix
pct_within_gender = counts.div(counts.sum(axis=0), axis=1) * 100 ax = pct_within_gender.plot(kind='bar') ax.set_ylabel('% of segments within gender') ax.set_xlabel('Topic ID') ax.legend(title='Gender') plt.tight_layout()
3) Difference plot: which topics are relatively more female/male?
diff = pct_within_gender['F'] - pct_within_gender['M'] ax = diff.sort_values().plot(kind='barh') ax.set_xlabel('F% - M% (within gender)') ax.set_ylabel('Topic ID') plt.tight_layout()
If you insist on pies pythonCopyEdit# Two pies, one per gender fig, axes = plt.subplots(1, 2, figsize=(10,5)) for ax, g in zip(axes, ['F', 'M']): pct_within_gender[g].plot(kind='pie', ax=ax, autopct='%1.1f%%', legend=False) ax.set_ylabel('') ax.set_title(f'Topic mix – {g}') plt.tight_layout()
What to report
Largest over/under-representations: topics where F%−M% is highest/lowest.
Volume + share: combine a bar for total segments per topic with colored segments (F/M) or annotate the difference next to it.
Optionally add confidence intervals or a quick chi-square test to state whether the distribution differs by gender overall.
If you tell me which of these styles you prefer (or share the data), I can generate the exact plots and percentages for you.