Change dynamically the contents of a matplotlib plot

后端 未结 3 1897
灰色年华
灰色年华 2020-12-28 11:13

I while ago, I was comparing the output of two functions using python and matplotlib. The result was as good as simple, since plotting with matplotlib is quite easy: I just

相关标签:
3条回答
  • 2020-12-28 11:39

    I really like using traits. If you follow the tutorial Writing a graphical application for scientific programming , you should be able to do what you want. The tutorial shows how to interact with a matplotlib graph using graphical user interface.

    0 讨论(0)
  • 2020-12-28 11:50

    Well I managed to do it with an event handler for mouse clicks. I will change it for something more useful, but I post my solution anyway.

    import matplotlib.pyplot as plt
    
    figure = plt.figure()
    # plotting
    plt.plot([1,2,3],[10,20,30],'bo-')
    plt.grid()
    plt.legend()
    
    def on_press(event):
        print 'you pressed', event.button, event.xdata, event.ydata
        event.canvas.figure.clear()
        # select new curves to plot, in this example [1,2,3] [0,0,0]
        event.canvas.figure.gca().plot([1,2,3],[0,0,0], 'ro-')
        event.canvas.figure.gca().grid()
        event.canvas.figure.gca().legend()
        event.canvas.draw()
    
    
    figure.canvas.mpl_connect('button_press_event', on_press)
    
    0 讨论(0)
  • 2020-12-28 12:06

    Sounds like you want to embed matplotlib in an application. There are some resources available for that:

    • user interface examples
    • Embedding in WX
    0 讨论(0)
提交回复
热议问题