Color Me Curious: Giving Genre Some Style

Day 43 of 100 Days Coding Challenge: Python

I kept tinkering with the tracker I built yesterday, chasing a dream—a dream of colors. Specifically, I wanted each book genre to appear in a different color in the graph from my Python book tracker genre visualization. That’s when I realized: my genre list was… how should I say it… ambitious. Turns out, tracking every tiny genre variation from “Science Memoir” to “Neo-Futurist Romance” makes the visualization look like a unicorn exploded on a bar chart.

To simplify, I added a new column for broader genres—less chaotic, more chart-friendly. My vision was to see a beautiful stacked histogram by genre color, but the code didn’t quite cooperate at first. It also made me realize something bigger: if I want this program to be truly useful, I’ll have to rethink how I track my books moving forward. Retroactively cleaning up all that old data? That’s a future-me problem. For now, this code is more about going forward than going backward.

Today’s Motivation / Challenge

If data is the new oil, then visualizing it is like turning that oil into fuel. Today’s challenge was about clarity—seeing reading habits at a glance. Colors help your brain grasp information faster, and genre-based colors are like putting your bookshelf on a rainbow diet. Also, it’s just more fun to look at.

Purpose of the Code (Object)

This program reads your book-tracking log and turns it into a visual chart, showing how many pages you’ve read each month. It highlights your genre diversity using color-coded bars, so you can instantly see if you’re stuck in a romance rut or finally diversifying your literary diet.

AI Prompt:

Add the existing Python code a color code for the following: Fantasy, Science Fiction….. History Fiction. 

Functions & Features

  • Add a new book to your reading log
  • Import books from another CSV file
  • List all books you’ve logged
  • Show a reading progress chart by month
  • Show a stacked genre-colored chart to compare reading trends

Requirements / Setup

You’ll need:

pip install pandas matplotlib

This code runs on Python 3.9+ (but most 3.x versions will do).

Minimal Code Sample

df[‘Genre’] = df[‘Genre’].str.strip().str.title()

df = df[df[‘Genre’].isin(GENRE_COLORS.keys())]

Standardize the genre format and filter out undefined genres so colors work correctly.

Book Tracker

Notes / Lessons Learned

Today, I had a brand new flavor of problem. You know the kind—where the code technically runs, but nothing happens? Turns out, I completely forgot to add:

if __name__ == “__main__”:

    main()

So the script just… stared at me, judging my oversight in silence. Classic rookie move.

But wait, there’s more. My bar chart decided that “colorful” meant “one color only.” Why? Because my genre strings were a mess—some had leading spaces, others were lowercase, and a few were practically jazz solos. After several rounds of trial and error (and a little sulking), I discovered this trick:

df[‘Genre’] = df[‘Genre’].str.strip().str.title()

instead of the other way around. And when I added this line to filter only the genres I’d actually assigned colors to:

df = df[df[‘Genre’].isin(GENRE_COLORS.keys())]

it finally worked. The chart bloomed into the colorful visualization I’d hoped for—like spring after debugging winter.

Optional Ideas for Expansion

  • Add a pie chart showing the overall genre distribution
  • Include a “favorite author” stat based on frequency
  • Let users define their own genre-color mappings in a config file

Leave a Reply

Your email address will not be published. Required fields are marked *