Day 44 of 100 Days Coding Challenge: Python
Yesterday’s mission? Make a colorful genre-based bar chart that didn’t look like a monochrome mess. After some wrestling with the code (and maybe whispering a few stern words to matplotlib), I decided to step back and take a wiser approach—add one function at a time. Think of it like seasoning a dish: too many spices at once and you can’t tell if the problem is the salt or the cinnamon.
So today, instead of fixing every chart in one go, I added something deliciously simple: a pie chart. Not the edible kind, unfortunately, but a visual feast for genre distribution. It’s a nice way to get a bird’s-eye view of what I’ve been reading—am I balanced, or living in a fantasy bubble? This project is starting to feel like a real book journal app, and that’s both exciting and mildly terrifying.
Today’s Motivation / Challenge
Histograms are great if you’re obsessed with dates (hi, it’s me), but sometimes you just want to know what you’ve been feeding your literary diet. A pie chart offers a big-picture summary of your reading preferences—like stepping back from the bookshelf and realizing 60% of it is purple dragon covers. Today’s goal? See the forest, not just the monthly genre trees.
Purpose of the Code (Object)
This updated code adds a neat little pie chart showing the proportion of each genre in your reading log. It uses the data already stored in your CSV file and the color settings from yesterday’s code. The result? A clean visual breakdown of your book habits, so you can brag about how “diverse” your library is—or realize it’s time to mix in something besides historical fiction.
AI Prompt:
Make it readable. Make it modular. And for the love of Python, add one feature at a time.
Functions & Features
- Add books to a CSV file with metadata like title, author, pages, and genre
- Show reading progress over time (bar chart by month and genre)
- View genre-specific reading patterns
- Display a pie chart of your overall genre distribution
- Import book lists from another CSV file
Requirements / Setup
- Python 3.x
Install the required library:
pip install matplotlib pandas
Minimal Code Sample
def plot_genre_distribution():
df = pd.read_csv(FILE_NAME)
df[‘Genre’] = df[‘Genre’].str.strip().str.title()
genre_counts = df[‘Genre’].value_counts()
colors = [GENRE_COLORS.get(g, ‘gray’) for g in genre_counts.index]
plt.pie(genre_counts, labels=genre_counts.index, colors=colors, autopct=’%1.1f%%’)
plt.title(‘Overall Genre Distribution’)
plt.axis(‘equal’)
plt.tight_layout()
plt.show()
This function creates a genre pie chart based on the books you’ve read.
Notes / Lessons Learned
What I added today was the code to create a pie chart, showing the distribution of genres. Then, I gave it a shiny new menu option. It worked surprisingly smoothly—probably because I didn’t try to fix five other things at the same time.
I’m finally getting used to virtual environments, which means fewer self-inflicted typos and wild goose chases through the wrong folders. The genre color dictionary I built yesterday made the pie chart almost too easy. That’s a nice surprise in coding: sometimes past-you actually set present-you up for success.
Also, here’s a bit of wisdom from building queries in SAP (and now in Python): change one thing at a time. If you break something, at least you know which line of code betrayed you.
Optional Ideas for Expansion
- Let users toggle between the pie chart and the bar chart from the same menu
- Allow subgenre tracking with drill-down options
- Export the pie chart as an image to share or embed in a blog
