Plotting the data with scrollable x (time/horizontal) axis on Linux

前端 未结 2 1454
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 12:21

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 followi

2条回答
  •  一个人的身影
    2020-11-30 12:29

    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], axisbg=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()
    

提交回复
热议问题