0

私は考古学者で、6x6 の正方形のグリッドに配置された発掘調査の結果を処理しています。各正方形は 5 mx 5 m です。
発掘調査で見つかった出土品の分布をグリッドにプロットしたいと考えています。

Excel データベースの値を 6x6 の Python/Pygame グリッドに表示したいと考えています。
誰かが私にこれを行う方法を教えてください。
Python で Excel ドキュメントを読み取る方法は知っていると思います*.csvが、グリッドに表示できません。

データに関する編集 データ
のスニペットはリンクにあります。「分類」列の項目をグリッドに表示したいと思います。 http://i48.tinypic.com/2rdgn02.jpg

たとえば
、各正方形の「準備フレーク」の数は、数字または色/形状のいずれかであり、各正方形は列 S のグリッド正方形番号に対応しています。データベースは非常に大きくなっています。
したがって、
理想的には、プログラムを継続的に変更することなく、プログラムがデータベースを読み取って正方形を更新するようにしたいと考えています。

コードは次のようになりました。

<import csv
 import os

 import pygame

# the functions for display
def disp(phrase,loc,screen):   # function to display phrase at loc on surface.
     s = font.render(phrase, True, (255,255,255))
     screen.blit(s, loc) #

def text_display_csv(filename,surface):
    '''Display .csv file contents on surface'''
    f = csv.reader(open("Flint catalogue v1.7 4 Feb 13 2013.csv")) # open the csv file      in one line!

    for row in f:
        y = f.line_num                # assign y as Row no.
        for x,item in enumerate(row): # Get column number(x) and item
        disp(item, (64*x+10,64*y+10), surface) # display item



pygame.init()
pygame.font.init()
font = pygame.font.SysFont("Courier",36) # font initialisation
screen = pygame.display.set_mode((800,600))


# the part you want to see
text = [str(i) for i in range(36)] # raw data!
text_display_csv(text,screen) # text is displayed
pygame.display.update() # screen updated

# Main loop, does nothing! :)
running = True
while running:
     for event in pygame.event.get():
         if event.type == pygame.QUIT:
             running = False
             pygame.quit()
             break
         if not running:
            break

もし可能ならば。各数字が四角形の準備フレークの数を表す下図のような方法で結果を表示したいと思います。 http://i49.tinypic.com/f39hxv.png

私はどんな助けにもとても感謝しています。これが意味をなさない場合は言ってください

トム

4

1 に答える 1

0

使用しているデータの種類を教えてくれなかったので、
整数を使用しましたが、任意の文字列が機能します。

Pygameで文字列(この場合は数値)
を含む A Grid を表示する方法は次のとおりです。

import pygame

# the functions for display
def disp(phrase,loc,screen):   # function to display phrase at loc on surface.
    s = font.render(phrase, True, (255,255,255))
    screen.blit(s, loc) #

def text_display(data,surface):
    '''display your data(list/tuple),containing strings on surface'''
    for x in range(6):         # your data is in 6 X 6 grid
        for y in range(6):
            disp( data[x+(y*6)], (64*x+10,64*y+10), surface)
            # 64 is the distance between 2 strings and 10 is the offset

pygame.init()
pygame.font.init()
font = pygame.font.SysFont("Courier",36) # font initialisation
screen = pygame.display.set_mode((400,400))

text = [str(i) for i in range(36)] # raw data!
text_display(text,screen) # text is displayed
pygame.display.update() # screen updated

# Main loop, does nothing! :)
running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
            pygame.quit()
            break
    if not running:
        break

これにより、

グリッド画像



よくトムを更新
してください。csvファイルの場合、この関数をスクリプトに追加して、代わりに使用できますtext_display

def text_display_csv(filename,surface):
    '''Display .csv file contents on surface'''
    f = csv.reader(open(filename)) # open the csv file in one line!

    for row in f:
        y = f.line_num                # assign y as Row no.
        for x,item in enumerate(row): # Get column number(x) and item
            disp(item, (64*x+10,64*y+10), surface) # display item

私はそれをテストしていないので、動作するかどうか教えてください。

更新 2最初のコード ブロックに、 and
を追加します。text_display_csv

変化する

text = [str(i) for i in range(36)] # raw data!
text_display(text,screen) # text is displayed
pygame.display.update() # screen updated

filename = 'the .csv file'
text_display_csv(filename,screen) # text is displayed
pygame.display.update() # screen updated

コードが機能するように。(必要に応じて間隔とオフセットを変更します)

于 2013-02-05T11:33:01.220 に答える