0

我正在使用 R 绘制一些图表。当我运行程序时,绘图出现然后很快消失。我怎样才能让情节留下来?

我正在运行在 Python 的动态时间规整中找到的以下代码

import numpy as np

import rpy2.robjects.numpy2ri
from rpy2.robjects.packages import importr

# Set up our R namespaces
R = rpy2.robjects.r
DTW = importr('dtw')

# Generate our data
idx = np.linspace(0, 2*np.pi, 100)
template = np.cos(idx)
query = np.sin(idx) + np.array(R.runif(100))/10

# Calculate the alignment vector and corresponding distance
alignment = R.dtw(query, template, keep=True)4
plot(alignments)
dist = alignment.rx('distance')[0][0]

print(dist)

基本上主文件在python中,我已经安装了rpy2,我正在远程连接到一台unix机器。现在情节出现了,但立即消失了。这只发生在 R 图上。当我运行 matplotlib 绘图时,它们会保留(不会消失)。所以我想知道我是否必须输入一些代码才能使情节“停留”。例如像matlab“holdon”。

4

1 回答 1

1

One solution would be to wait for the user to type "enter" before the program finishes:

raw_input("Please type enter...")

This is also useful with my Matplotlib plots (instead of using pyplot.show(): this closes all the plots automatically).

PS: I just saw that this was suggested in the link from the comments to the original question. I approve. :)

于 2013-05-22T03:12:49.087 回答