Внедрить функцию _update_plot в PyQt matplotlib - PullRequest
0 голосов
/ 21 марта 2019

вот моя программа обновления графика, которую я хочу поместить в окно pyqt5.

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

Любая помощь / совет приветствуется

Программа:

import math
import matplotlib.pyplot as plt
import matplotlib.animation as animation
import numpy as np
from matplotlib.widgets import Slider, Button, RadioButtons
from matplotlib import style

style.use('seaborn-poster')
def _update_plot(i, fig, scat, l,l2):

        M = ((math.sin(math.radians(i))*7.5)-(math.sin(math.radians(i/2))*9))/((math.cos(math.radians(i))*7.5)-(math.cos(math.radians(i/2))*9))

        g = M*(15-(math.cos(math.radians(i/2))*9))+(math.sin(math.radians(i/2))*9)


        scat.set_offsets(([math.cos(math.radians(i))*7.5, math.sin(math.radians(i))*7.5], [math.cos(math.radians(i/2))*9, math.sin(math.radians(i/2))*9], [0, 0]))

        if (i>=540) or (i<=180):
                l.set_data(([math.cos(math.radians(i))*7.5,math.cos(math.radians(i/2))*9],[math.sin(math.radians(i))*7.5,math.sin(math.radians(i/2))*9]))
                l2.set_data(([math.cos(math.radians(i/2))*9,15],[math.sin(math.radians(i/2))*9,g]))
        else:
                l.set_data(([0,0],[0,0]))
                l2.set_data(([0,0],[0,0]))


        return [scat,l,l2]



fig = plt.figure()


x = [0]
y = [0]

ax = fig.add_subplot(111)
ax.set_aspect('equal')
ax.grid(True, linestyle = '-', color = '0.10')
ax.set_xlim([-15, 15])
ax.set_ylim([-15, 15])

l, = plt.plot([],[], '-', zorder=1)
l2, = plt.plot([],[], '-', zorder=2)
scat = plt.scatter(x, y, c = x, zorder=3)
scat.set_alpha(0.8)

anim = animation.FuncAnimation(fig, _update_plot, fargs = (fig, scat, l,l2),
                               frames = 720, interval = 10)

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