我正在讀取文本文件,並從該文本文件中找到想要生成matplotlib的熱圖。這是到目前爲止我的代碼:使用Matplotlib而不使用pcolor/pmesh的熱圖
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()
到這裏,我堅持,我想用RGB方法matplotlib到specifiy每種顏色一個「盒子」的比例情節了。
當我運行這個它給我這樣的畫面:
因此,我怎麼一個特定的顏色添加到特定的盒子? (如果這是4x4將會有16個盒子,並且我想知道如何爲每個盒子添加顏色)
您能否提供一些數據並更詳細地描述您的預期結果? – Cleb