Определение уникального идентификатора для 3D-анимации бара, matplotlib - PullRequest
0 голосов
/ 03 февраля 2020

Извините, если мой заголовок очень неясен. Я работаю над анимацией, которая представляет гистограмму всех чисел во время сканирования файла.

Я пытаюсь получить уникальный идентификатор, но все они возвращают один и тот же идентификатор. Затем я подумал об установке уникального идентификатора, но я не совсем уверен, как это сделать. Я думал, что если бы я мог просто изолировать результат в последовательности, чтобы он представлял собой собственный бар, я мог бы очистить его и затем обновить. Трудно представить, что происходит, вот изображение: The items at the beginning, without ID's, shouldn't be rendered

Вот код:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.animation as animation
import numpy as np
import random
from collections import defaultdict
from collections import deque
import re

color = f"#{random.randrange(0x1000000):06x}"
color_border = f"#{random.randrange(0x1000000):06x}"
range = [0,1,2,3,4,5,6,7,8,9]
digit_finder = re.compile(r'(\d+)')
fig = plt.figure()
ax = fig.add_subplot(111, projection= '3d')
ax.set_xticks(range)
#def text_crawler(file, place, bptrial):

def animate(i):
    global z_line
    global color
    global color_border

    _last = _f.readlines(20)
    for line in _last:
        _line = line.decode("utf-8")
        final = digit_finder.findall(_line)
        #if not final: continue
        print(final[1])
        z_line.append(int(final[1]))

    for z in z_line:
        squared_num = createdict(str(z))
    xs = list(squared_num.keys())
    ys = list(squared_num.values())

    #ax.clear()
    ax.bar(xs, ys, zs=z ,zdir='y', color = color, alpha=0.8,
    linewidth=3, edgecolor = color_border)
    ax.set_yticks(z_line)
    ax.set_xticks(range)
    print(Axes3D.bar)



def createdict(it):
    x = defaultdict(int)
    for k in it:
        x[k] += 1
    return  x
count = 10
#final = list(map(lambda x: createdict(x), nums))

with open('graph_index.txt', 'rb') as index_reader:
    i_first = index_reader.readline()
    if not i_first:
        print('This is where you return index = 0')
    index_reader.seek(-2, 2)
    while index_reader.read(1) != b"\n":
            index_reader.seek(-2,1)
    i_last = index_reader.readline().decode("utf-8")
    index = digit_finder.findall(i_last)
    if not index:
        print('This is also index = 0...just in case.')
    else:
        print(int(index[0]), 'This should be a number, in bytes, where you will continue from.')

z_line = deque([],maxlen=7)

with open('numbers.txt', 'rb') as _f:
    first = _f.readline(0)
    _f.seek(int(index[0]), 0)
    while _f.read(1) != b"\n":
        _f.seek(-2,1)
    ani = animation.FuncAnimation(fig, animate, interval=10000)
    print(ani)
    plt.show()```



Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...