функция animate для semporn lmplot с обновленным значением Hue - PullRequest
0 голосов
/ 27 августа 2018

Я пытаюсь сделать анимацию (FuncAnimation) с Seaborn. Анимация работает нормально, но значение hue, которым должен управлять столбец «Anomalous» в кадре данных, не обновляется и дает неверные результаты.
Как я могу исправить эту проблему, чтобы обновить также аномальный столбец со столбцами температуры и влажности?

from matplotlib import pyplot as plt
import pandas as pd
import numpy as np
import matplotlib.animation as animation
import matplotlib
import seaborn as sns

sensor_data_path='full_results.csv'
sns.set(rc={'figure.figsize':(8,8)})
sns.set(style='ticks')

def read_sensor_data():
    # I read the sensor data here 


def modify_file(csv_file):
    # I modify the sensor data to return the required chunk of the full file

def animate(i):
    for c in scatters:    
        results_file=read_sensor_data()
        results_file_copy=modify_file(results_file)
        results_file_copy=results_file_copy.reset_index(drop=True)
        xy=results_file_copy.loc[:,["temp_C","humid_%"]] 
        c.set_offsets(xy)
    txt.set_text('frame={:d}'.format(i))
    return scatters+[txt]    


x="temp_C"
y="humid_%"
csv_file=read_sensor_data()
g = sns.lmplot(x=x, y=y,data=csv_file,hue="Anomalous",
               markers=["o", "x"],legend_out = True, aspect=1.61, fit_reg=False)    
fig = g.fig
ax = g.axes[0,0]
scatters = [c for c in ax.collections if isinstance(c, matplotlib.collections.PathCollection)]
txt = ax.text(0.1,0.9,'frame=0', transform=ax.transAxes)


ani=animation.FuncAnimation(fig, animate, interval=5000, save_count=100, 
                            repeat=True, blit=False)
plt.show()
...