我对Python非常新,甚至我做了相当深入和长期的研究,我想我需要在社区中的确认,然后在github上打开一个案例。需要一个库缺陷的确认
我正在绘制两个"hinton plots"但我使用颜色范围来表示矩阵值。
由于某种原因使用子图绘制背景在最后一个子图第一个阴谋与第一个mymap
颜色(在我的情况是蓝色)。如果在任何情况下都覆盖set_facecolor = 'gray'
(即使我在绘图后设置背景颜色)。此外,我发现只有当matrix
值大于0时,此bug才会累积。
请参阅下面的图片(和图片说明)和代码。
第二个子图上第一张图片的背景为蓝色。 第三个子图添加了无数据,现在它是蓝色的,第二个子图的第一个平方不是。
对于第一画面效果变化6个行:fig, (axe_1, axe_2) = plt.subplots(1,2)
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
fig, (axe_1, axe_2, axe_3) = plt.subplots(1, 3)
my_min, my_max = (0, 10)
step = 1
mymap = mpl.colors.LinearSegmentedColormap.from_list("my list", ['blue','red'])
levels = range(my_min, my_max+step, step)
matrix = [None, None]
matrix[0] = np.asanyarray([[0, 1, 2], [3, 0, 5], [6, 7, 0]])
matrix[1] = np.asanyarray([[0, 9, 8], [7, 0, 6], [5, 4, 0]])
for iter, item in enumerate([axe_1, axe_2]):
item.patch.set_facecolor('gray')
item.set_aspect('equal', 'box')
item.xaxis.set_major_locator(plt.NullLocator())
item.yaxis.set_major_locator(plt.NullLocator())
Z = [[0, 0], [0, 0]]
CS3 = plt.contourf(Z, levels, cmap=mymap)
for (x, y), z in np.ndenumerate(matrix[iter]):
b = (float(z)-my_min)/(my_max-my_min)
g = 0
r = 1-b
rect = plt.Rectangle([y, x], 0.9, 0.9, facecolor=(r, g, b), edgecolor="black")
item.add_patch(rect)
item.autoscale_view()
plt.show()
如果我没有做任何愚蠢的错误,你会确认这是一个错误,我会打开GitHub上的问题。
你能更清楚地知道你的问题是什么吗? –
更新的问题,我希望现在更清楚。 – arbulgazar