pythonファイルに別のpythonファイルを実行させて、グラフ上にプロットするためのランダムなy値を得ることはできますか?もしそうなら、これについてどうやって行くのですか?私にPythonファイルは、リアルタイムグラフにプロットする点を生成します
import time
import random
from collections import deque
from matplotlib import pyplot as plt
from matplotlib import style
import Random_Generation_List
start = time.time()
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([], [], "g-")
self.axes.set_autoscaley_on(True)
def add(self, x, y):
self.axis_x.append(x)
self.axis_y.append(y)
values = Random_Generation_List.getvalues()
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
print(values)
def animate(self, figure, callback, interval = 50):
def wrapper(frame_index):
self.add(*callback(frame_index))
self.axes.relim(); self.axes.autoscale_view() # rescale the y-axis
return self.lineplot
def main():
style.use('dark_background')
fig, axes = plt.subplots()
display = RealtimePlot(axes)
axes.set_title("Real-time Plot")
axes.set_xlabel("Time")
axes.set_ylabel("Amplitude")
while True:
display.add(time.time() - start, random.random() * 100)
plt.pause(0.001)
display.animate(fig, lambda frame_index: (time.time() - start, random.random() * 100))
plt.show()
if __name__ == "__main__": main()
方法:
import random
import threading
def main():
for count in range(12000):
y = random.randint(0,10000)
print(y)
def getvalues():
return [random.randint(0, 1000) for count in range(12000)]
def coordinate():
threading.Timer(0.0001, coordinate).start()
coordinate()
main()
とランダムな値を使用してグラフを生成したファイル(式が埋め込まれた):
現在、私は、ランダムなyの値のリストを生成したファイルを持っていますこれらを組み合わせてファイルを実行して、y(xは時間)として使用する乱数を生成し、このグラフにリアルタイムでプロットしますか?
ありがとうございます!
最初のファイルのコードを変更することはできますか? oその 'print(y)'文からの出力をキャプチャしますか?別のファイルでなければならないのですか、プロットプログラムにコードを追加するだけですか? – Prune