Python Forum
connecting the first point to the last point Matplotlib
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
connecting the first point to the last point Matplotlib
#1
I wanted to plot by using matplotlib library to plot data frames that read from database SQL without using plt.pause so I created a class to plot and animate the data but the problem is the last point is connected to the first point by a line
class RealtimePlot:
    def __init__(self, axes, max_entries = 100):
        self.axis_x = deque(maxlen=max_entries)
        self.axis_y = deque(maxlen=max_entries)
        self.axes = axes
        self.max_entries = max_entries
        
        self.lineplot, = axes.plot([], [], "ro-")
        self.axes.set_autoscaley_on(True)

    def add(self, x, y):
        self.axis_x.append(x)
        self.axis_y.append(y)
        self.lineplot.set_data(self.axis_x, self.axis_y)
        self.axes.set_xlim(self.axis_x[0], self.axis_x[-1] + 1e-15)
        self.axes.relim(); self.axes.autoscale_view() # rescale the y-axis

    def animate(self, figure, callback, interval = 50):
        import matplotlib.animation as animation
        def wrapper(frame_index):
            self.add(*callback(frame_index))
            self.axes.relim(); self.axes.autoscale_view() # rescale the y-axis
            return self.lineplot
        animation.FuncAnimation(figure, wrapper, interval=interval)
The workaround that I tried to sort the data as I searched on StackOverflow and other websites also I didn't solve the problem any help would be appreciated if the whole code is required I would post it.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  point transformation software in space johnjsi 2 340 Feb-01-2024, 01:31 AM
Last Post: johnjsi
  finding point in m grid jenya56 0 797 Feb-06-2022, 09:00 PM
Last Post: jenya56
  [SOLVED] Read text file from some point till EOF? Winfried 1 1,911 Oct-10-2021, 10:29 PM
Last Post: Winfried
  Why are two variables unequal as they point to the same value? fc5igm 4 2,670 Jun-08-2021, 02:41 PM
Last Post: fc5igm
  Matplotlib: How do I convert Dates from Excel to use in Matplotlib JaneTan 1 3,163 Mar-11-2021, 10:52 AM
Last Post: buran
  Python Matplotlib: How do I plot lines with different end point in the same graph? JaneTan 0 1,553 Feb-28-2021, 11:56 AM
Last Post: JaneTan
  SimplyGIS query point-value stampy 2 1,508 Feb-10-2021, 10:10 AM
Last Post: stampy
Question How to make a button always stay on a point when resizing the window? _ShevaKadu 5 4,082 Nov-04-2020, 03:59 PM
Last Post: deanhystad
  Printing digits after the decimal point one by one uberman321 1 1,705 Oct-20-2020, 08:10 AM
Last Post: bowlofred
  wireless access point on raspberry PI zazas321 0 1,902 Oct-02-2020, 05:33 PM
Last Post: zazas321

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020