在Linux上使用可滚动的X轴(时间/水平)对数据进行绘图

8
我想绘制一个x轴较长的数据图。如果我绘制整个x轴,则图形会缩小,几乎无法阅读。我在SO上找到了这个答案,其中提到了以下scipy/matplotlib代码。但是当我尝试运行上述代码时,出现以下错误:
Traceback (most recent call last):
  File "scrollingPlot.py", line 88, in <module>
    app = MyApp()
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_core.py", line 8628, in __init__
    self._BootstrapApp()
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_core.py", line 8196, in _BootstrapApp
    return _core_.PyApp__BootstrapApp(*args, **kwargs)
  File "scrollingPlot.py", line 82, in OnInit
    self.frame = MyFrame(parent=None,id=-1)
  File "scrollingPlot.py", line 21, in __init__
    self.scroll_range)
  File "/usr/lib/python2.7/dist-packages/wx-3.0-gtk2/wx/_core.py", line 11226, in SetScrollbar
    return _core_.Window_SetScrollbar(*args, **kwargs)
wx._core.PyAssertionError: C++ assertion "sb" failed at ../src/gtk/window.cpp(4754) in SetScrollbar(): this window is not scrollable

PS: 其他方案也是可以接受的(最好是Python、R或其他简单且多平台的解决方案)

PPS: 我已经发布了问题,涉及到了上述错误

2个回答

15

你考虑过使用matplotlib 滑块小部件 吗?

这里有一段简单的代码,仅供参考。

import numpy as np
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider

fig, ax = plt.subplots()
plt.subplots_adjust(bottom=0.25)

t = np.arange(0.0, 100.0, 0.1)
s = np.sin(2*np.pi*t)
l, = plt.plot(t,s)
plt.axis([0, 10, -1, 1])

axcolor = 'lightgoldenrodyellow'
axpos = plt.axes([0.2, 0.1, 0.65, 0.03], facecolor=axcolor)

spos = Slider(axpos, 'Pos', 0.1, 90.0)

def update(val):
    pos = spos.val
    ax.axis([pos,pos+10,-1,1])
    fig.canvas.draw_idle()

spos.on_changed(update)

plt.show()

这就是我一直在寻找的解决方案。谢谢。 - Wakan Tanka

-2
R 中, this answer 可能会对你有所帮助。它可以将绘图保存为单独的 PNG 格式,但是你也可以使用其他命令来更改格式类型。以下是该答案中相关的代码:
 png("wide.png", width = 1e5, height = 500)
 plot((sin(1:10000/100)+rnorm(10000)/5),type='l')
 dev.off()
 #bmp("wide.bmp", width = 1e5, height = 500)
 #plot((sin(1:10000/100)+rnorm(10000)/5),type='l')
 #dev.off()
 #note that the png has a size of 396 KB, while the bmp has 48,830 KB.

谢谢,这是一个有趣的想法。如果matplotlib不可用,它可能会派上用场,否则@Noel Segura的解决方案似乎很好。 - Wakan Tanka

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接