在 Linux 上使用可滚动的 x(时间/水平)轴绘制数据 [英] Plotting the data with scrollable x (time/horizontal) axis on Linux

查看:23
本文介绍了在 Linux 上使用可滚动的 x(时间/水平)轴绘制数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想绘制 x 轴较长的数据.如果我绘制整个 x 轴,那么绘图会缩小并且几乎无法读取.我在 SO 上找到了 this 答案它指向以下 scipy/matplotlib 代码.但是当我尝试运行上述代码时,出现以下错误:

I want to plot data where x axis is long. If I plot the whole x axis then the plot shrinks and it is almost unreadable. I've found this answer on SO which points to following scipy/matplotlib code. But When I try to run the mentioned code I get following error:

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或一些简单和多平台的东西)

PS: Other solutions are also welcomed (preferably python, R, or something simple and multi platform)

PPS:我已针对上述错误打开了问题

PPS: I've opened the issue for mentioned error

推荐答案

您是否考虑过使用 matplotlib 滑块小部件?

Have you considered using matplotlib slider widgets?

这里有一些代码只是为了展示

Here is a little code just to show as example

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()

这篇关于在 Linux 上使用可滚动的 x(时间/水平)轴绘制数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆