Kivy和Matplotlib? [英] Kivy and matplotlib?

查看:128
本文介绍了Kivy和Matplotlib?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想知道matplotlib是否与kivy 1.9.0兼容,如果可能的话我该如何实现呢?如果不支持它,那么kivy是否有与之非常相似的东西?

I just wanted to know if matplotlib is compatible with kivy 1.9.0, and how I do I go about implementing it if it's possible? If it's isn't supported, does kivy have something very similar to it?

我希望能够从我的kivy应用程序中的一个程序中使用此特定代码:

I want to able use this particular code from one my programs in my kivy app:

def printPieChart(table, column):
    if column == 6:
        columnList = table.iloc[:, -1:].values.T.ravel()
    else:
        columnList = table.iloc[:, (column - 7): (column - 6)].values.T.ravel()
    countedList = Counter(columnList)

    #set up the size of the pie chart
    fig = plt.figure(figsize=[10, 10])
    ax = fig.add_subplot(111)
    cmap = plt.cm.prism

    #input variables for pie function
    slices = [float(v) for v in countedList.values()]
    colors = cmap(np.linspace(0., 1., len(slices)))
    labels = [float(k) for k in countedList]
    columnHeaders = list(table.columns.values)

    #the pie chart
    pie_wedge_collection = ax.pie(slices, colors = colors, labels = labels, labeldistance = 1.05, autopct = '%1.1f%%')
    #get rid of the black outlines between the wedges and around the pie
    for pie_wedge in pie_wedge_collection[0]:
        pie_wedge.set_edgecolor('white')
    ax.set_title(columnHeaders[column + 1])

如果我想为matplotlib编写一个编译配方,会遵循这些原则吗?

If I wanted to make a compilation recipe for matplotlib would it be along these lines?

#!/bin/bash

VERSION_matplotlib=${VERSION_matplotlib:-1.4.3}
DEPS_matplotlib=(numpy python dateutil pyparsing six linpng pytz freetype agg PyCXX qhull ttconv)
URL_matplotlib=http://pypi.python.org/packages/source/m/matplotlib/matplotlib-$VERSION_matplotlib.tar.gz
MD5_matplotlib=f43c20480a1673185afefc7d4848a1d2
BUILD_matplotlib=$BUILD_PATH/matplotlib/$(get_directory $URL_matplotlib)
RECIPE_matplotlib=$RECIPES_PATH/matplotlib

# function called for preparing source code if needed
# (you can apply patch etc here.)
function prebuild_matplotlib() {
    true
}

function shouldbuild_lxml() {
    if [ -d "$SITEPACKAGES_PATH/matplotlib" ]; then
        DO_BUILD=0
    fi
}

# function called to build the source code
function build_matplotlib() {
    cd $BUILD_matplotlib

    push_arm

    export CC="$CC -I$BUILD_numpy/"
    export LDFLAGS="-L$BUILD_numpy/numpy/.libs -L$BUILD_numpy/numpy/.libs -L$BUILD_numpy/.libs -L$BUILD_numpy/numpy -L$BUILD_numpy/numpy -L$BUILD_numpy/  $LDFLAGS"
    export LDSHARED="$LIBLINK"

    chmod +x $BUILD_numpy/numpy-config
    export PATH=$PATH:$BUILD_numpy
    #plus more for the other dependencies
    try $HOSTPYTHON setup.py build_ext -I$BUILD_matplotlib
    try find . -iname '*.pyx' -exec $CYTHON {} \;
    try $HOSTPYTHON setup.py build_ext -v
    try find build/lib.* -name "*.o" -exec $STRIP {} \;

    export PYTHONPATH=$BUILD_hostpython/Lib/site-packages
    try $BUILD_hostpython/hostpython setup.py install -O2 --root=$BUILD_PATH/python-install --install-lib=lib/python2.7/site-packages

    unset LDSHARED
    pop_arm
}

# function called after all the compile have been done
function postbuild_matplotlib() {
    true
}

推荐答案

您可以像平常一样从kivy脚本中很好地调用matplotlib,但是kivy没有内置的显示图的方式-您必须获得使用matplotlib进行渲染(例如,png格式,或者您可以尝试kivy的实验性svg支持,但可能会有问题),然后将其显示在Image小部件或类似的窗口中.

You can call matplotlib from a kivy script fine, exactly as you normally would, but kivy has no built in way to display plots - you'd have to get matplotlib to render them (e.g. as png, or you could try kivy's experimental svg support but it might be buggy) then display them in an Image widget or similar.

如果要在android或ios上执行此操作,则需要matplotlib的编译配方,因为我认为我们还没有.我认为这应该不太难,如果您有兴趣,我们很乐意与您讨论.

If you want to do this on android or ios, you'd need a compilation recipe for matplotlib, as I don't think we have one yet. I think that shouldn't be too hard and we'd be happy to discuss if if you're interested.

我们确实有一名GSoC学生正在努力为我们提供适当的matplotlib支持,因此在接下来的几个月中可能会有好消息.

We do have a GSoC student working on giving us proper matplotlib support, so there may be good news on it in the next few months.

这篇关于Kivy和Matplotlib?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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