python可以制作Matlab风格的GUI

时间:2013-03-19 17:59:20

标签: python matlab wxpython tkinter

我真的想要爱上Python并远离Matlab。是否可以在Python中制作Matlab样式的GUI?相比之下它有多容易? (我以编程方式制作matlab GUI,不敢使用GUIDE)我可以将matplotlib图形放在这些GUI中吗? tk或wx(或其他东西)对此更好吗?

3 个答案:

答案 0 :(得分:1)

以前没有使用过Matlab,不确定它的GUI。但是如果你倾向于以交互方式使用Python,你可能想尝试一下iPython。使用Qt的Ipython可以为您呈现优雅的GUI。

答案 1 :(得分:1)

wxPython有制表符,网格或ListCtrls(即表格),并支持matplotlib和PyPlot用于图形。您可以在以下链接中阅读有关使用matplotlib的信息:

要查看wxPython中包含的所有小部件,请访问www.wxpython.org并单击左侧的下载链接。你会发现他们有一个独立的Docs&演示包可以显示几乎每个小部件及其工作原理。

答案 2 :(得分:1)

对于简单的接口,您可能需要查看matplotlib提供的GUI中性小部件,在此处记录 - http://matplotlib.org/api/widgets_api.html

这是一个使用这些GUI中性小部件来绘制具有由三个滑块小部件控制的变量参数的函数的简单示例:

import functools
import numpy as np
import pylab
import matplotlib.pyplot as plt
from matplotlib.widgets import Slider, Button, RadioButtons, MultiCursor


def hillfxn(x, B, K, n):
    xn = float(x**n)
    return (B * xn)/(K**n + xn)


def draw_function(x, y, xlabel="Activator concentration (X)", 
                  ylabel="Promoter activity"):
    fig, ax = plt.subplots(1, 1, sharex=True)
    plt.subplots_adjust(left=0.15, bottom=0.25)
    lines = ax.plot(x, y)
    ax.set_xlabel(xlabel)
    ax.set_ylabel(ylabel)
    ax.set_ylim(0,max(y)*1.1)
    return fig, ax, lines

def draw_interactive_controls(n, B, K):
    axcolor = 'lightgoldenrodyellow'
    axK = plt.axes([0.1, 0.01, 0.75, 0.03], axisbg=axcolor)
    axB  = plt.axes([0.1, 0.06, 0.75, 0.03], axisbg=axcolor)
    axN  = plt.axes([0.1, 0.11, 0.75, 0.03], axisbg=axcolor)
    Nslider = Slider(axN, "$n$", 1, 10, valinit=n, valfmt='%1.3f')
    Bslider = Slider(axB, "$\\beta$", 0, 20, valinit=B, valfmt='%1.3f')
    Kslider = Slider(axK, "$K$", 0.01, 20, valinit=K, valfmt='%1.3f')       
    return Nslider, Bslider, Kslider

def update_plot(val, x=None, lines=None, ax=None, 
                Nslider=None, Bslider=None, Kslider=None):
    n = Nslider.val
    B = Bslider.val
    K = Kslider.val
    y = [hillfxn(i, B, K, n) for i in x]  
    lines[0].set_ydata(y)
    ax.set_ylim(0,max(y)*1.1)  
    pylab.draw()


if __name__ == "__main__":
    # initial values
    B, K, n = 5, 5, 1
    x= np.linspace(0,30,250)
    y = [hillfxn(i, B, K, n) for i in x]

    # setup initial graph and control settings
    fig, ax, lines = draw_function(x,y)
    Nslider, Bslider, Kslider = draw_interactive_controls(n, B, K)

    # specify updating function for interactive controls
    updatefxn = functools.partial(update_plot, x=x, lines=lines, ax=ax, 
                    Nslider=Nslider, Bslider=Bslider, Kslider=Kslider)

    Nslider.on_changed(updatefxn)
    Bslider.on_changed(updatefxn)
    Kslider.on_changed(updatefxn)
    pylab.show()

这将产生如下界面:

matplotlib GUI neutral widgets