I am reading a text file and from that text file I would like to generate a heat map with matplotlib. This is my code so far:
import matplotlib.pyplot as plt
import numpy as np
import math
from matplotlib import colors
file_object = open("tokillamockingbird.txt", "r", encoding="utf-8")
reading = file_object.read()
new_read = reading.strip()
someWord = ''
list_words = []
for letter in new_read:
if letter in ",!.?":
list_words.append(letter)
lenListWords = len(list_words)
lengthOfPunctuation = math.sqrt(lenListWords)
# generate a scaled plot for this
data = np.random.rand(lengthOfPunctuation,lengthOfPunctuation)
fig, axes = plt.subplots()
Up to here, I am stuck and I want to use RGB method in matplotlib to specifiy each color for a 'box' that the scaled plot has.
When I run this it is giving me this picture:
Therefore, how do I add a specific color to a specific box? (if this is 4x4 there will be 16 boxes and I want to know how to put a color to each box)