퍼콜 레이션과 관련된 과제를 수행하고 있습니다. 길고 간단한 이야기입니다. 그리드를 나타내는 배열 배열이 있으며 모든 항목은 -1, 0 또는 1입니다. 할당은 본질적으로 완료되었지만, 한 부분은 각 가능한 항목에 대한 색상을 사용하여 매트릭스의 그래픽 표현을 요구합니다. 그러나 할당이 사용되는 방식에서부터, 표준 Python 2.7 및 numpy에없는 항목을 사용해서는 안되는 것처럼 들립니다.행렬을 그래픽으로 표현하는 "가장 간단한"방법
필자는 어떻게하는지 생각할 수 없었습니다. 그래서 필라프를 가져 와서 모든 좌표를 산점도에서 큰 색의 사각형으로 플로팅했습니다. 그러나이 작업에 더 나은 패키지를 사용하는 것처럼 더 나은 방법이 있다는 잔소리가 있습니다. 또는 그냥 numpy로 처리하는 방법이 있습니다. 제안?
도움이 될 경우 현재 코드가 아래에 있습니다.
def show_perc(sites):
n = sites.shape[0]
# Blocked reps the blocked sites, etc., the 1st list holds x-coords, 2nd list holds y.
blocked = [[],[]]
full = [[],[]]
vacant = [[],[]]
# i,j are row,column, translate this to x,y coords. Rows tell up-down etc., so needs to
# be in 1st list, columns in 0th. Top row 0 needs y-coord value n, row n-1 needs coord 0.
# Column 0 needs x-coord 0, etc.
for i in range(n):
for j in range(n):
if sites[i][j] > 0.1:
vacant[0].append(j)
vacant[1].append(n-i)
elif sites[i][j] < -0.1:
full[0].append(j)
full[1].append(n-i)
else:
blocked[0].append(j)
blocked[1].append(n-i)
pl.scatter(blocked[0], blocked[1], c='black', s=30, marker='s')
pl.scatter(full[0], full[1], c='red', s=30, marker='s')
pl.scatter(vacant[0], vacant[1], c='white', s=30, marker='s')
pl.axis('equal')
pl.show()
이 관심을 가질만한 당신 http://stackoverflow.com/questions/902761/saving-a-numpy-array-as-an-image –
에 ANSI 이스케이프 시퀀스와 장식을 사용 할 수있을 것 텍스트의 컬러 코드 블록은 다음을 참조하십시오 : http://stackoverflow.com/questions/287871/print-in-terminal-with-colors-using-python – jmunsch