0

I have a data set of the following class:

class Event:

def __init__(self, timestamp, lx, ly, lz, nature):
    try:
        self.timestamp = datetime.strptime(timestamp, "%d/%m/%Y %H:%M")
    except:
        self.timestamp = datetime.strptime(timestamp, "%d/%m/%Y %H:%M:%S")
    self.x = lx
    self.y = ly
    self.z = lz
    self.nature = nature

the thing is I am trying to animate a scatter of these points over time in 3d where I would specify a delta t and starting from t0 I would iterate till t max where at each step the new scattered points are the ones that have t in the increment to the interval.
this is the sequential one I manged to do:

def animation_tremor_events(index_Event):
    dx, dy, dz = arr_s_t_points[index_Event, 0], arr_s_t_points[index_Event, 1], arr_s_t_points[index_Event, 2]
    print(dx, dy, dz)
    text.set_text("{:d}: [{:.0f},{:.0f},{:.0f}]".format(index_Event, dx, dy, dz))  # for debugging
    x.append(dx)
    y.append(dy)
    z.append(dz)
    graph._offsets3d = (x, y, z)
    return graph,

these are the important segments because the code is too long

ani = animation.FuncAnimation(fig, animation_tremor_events, frames=600, interval=0.001, save_count=5000)
plt.show()
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Ali11H
  • 11
  • 3
  • well, what I managed to do was more of a sequential plot which worked out but I haven't been able yet to make one that is time-driven, check the edited question. – Ali11H Feb 25 '22 at 13:39
  • The link between the two parts might be that your `Event` class somewhere stores the x-y-z data in an array `arr_s_t_points` but then the time information would be lost, as you only have the index for the animation count [as shown for instance here](https://stackoverflow.com/a/71214435/8881141). But you mention that you want to animate with a given timedelta. For this, you have to provide more information on how you store and filter your data. – Mr. T Feb 25 '22 at 14:23
  • well I managed to extract the data as a data class as the class event here and in another way as a PD data frame, but the main goal is to animate these points through time each time adding delta t only plotting the new points in the time interval – Ali11H Feb 25 '22 at 14:57
  • as for the filtering, I am removing some events according to their type then I sort according to their time t and reindex them. and for the storage, I moved the data into an np array which I filled and reshaped in order to plot them using 3d scatter – Ali11H Feb 25 '22 at 15:08
  • So, the class definition is not relevant to your question because the time information is stored somewhere in the numpy array/pandas dataframe? Please read [How do I ask a good question?](https://stackoverflow.com/help/how-to-ask) and [How to create a minimal, complete, and reproducible example](https://stackoverflow.com/help/minimal-reproducible-example). I would keep the data in a pandas dataframe as pandas has good functions to separate data based on datetimes and timedeltas. I cannot say much more to this broad question. – Mr. T Feb 25 '22 at 19:43
  • well, it is relevant but I am just saying I have another option if there is a way to do this animation with data frames instead of classes I won't mind it, it's just to give a wider range of suggestions. – Ali11H Feb 27 '22 at 11:17

0 Answers0