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

前端 未结 2 1421
佛祖请我去吃肉
佛祖请我去吃肉 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()
    
    0 讨论(0)
  • 2020-11-30 12:39

    In R this answer could help you. It will save the plot as a separate png, but you can change the format type with a different command. The relevant code from that answer is reproduced:

     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.
    
    0 讨论(0)
提交回复
热议问题