Qtiplot + Python provides tremendous graphing and data processing capabilities

    Today I will talk a little about the QtiPlot program and the possibility of scripting its capabilities using Python.

    The QtiPlot program is developed as a free analogue of Origin , that is, a universal tool for presenting and analyzing data. It allows you to build all kinds of graphs, perform data operations, search for approximations of curves, etc. I did not work with Origin from the first year of the institute, so I can’t compare the possibilities, and it doesn’t matter, QtiPlot has three major advantages: it is free, cross-platform and Python scripting, which will be discussed later.

    Currently, the "de facto standard" for charting the world * nix systems is gnuplot, in the Windows world, this is Origin, apparently broken if you look at its cost (a little less than $ 1000 for the coolest version). So QtiPlot in place with Python may well squeeze these products.

    First we need to install qtiplot. This is best done from the repositories of your distribution, because this with a big guarantee means that all libraries will be linked correctly (for example, for opensuse 11.1 ). You can take the binary from the site, but it is linked against python 2.5, and now almost everyone already has 2.6, you can also compile it yourself, but it's not so simple. By the way, speaking, here we are faced with an example of paid free software. Windows users can only download the demo version, the full version costs money. Well, or they can compile themselves. Or find on the Internetalternative assembly . And you can buy, it costs only 20 euros, compared with the origin just a penny.

    NB * nix users! Before installation, you need to make sure that Python and the python-sip package are installed, without this scripting will not work.

    The second step is to enable script support, for this we need the qtiplotrc.py and qtiUtil.py initialization files. Unfortunately, they made a mistake, without which scripting will work, so it’s better to download the files from me. We put them in some place, for example ~ / .qtiplot / and run qtiplot. Next View -> Preferences -> General -> File Locations select the directory where we put the files. Now all that remains is to turn on the python, Scripting -> Scripting Language -> Python and open the console View -> Console. The console should contain the inscription "python is ready" if you use my files. In fact, this is not a console at all, but the output of cout, which is somewhat disappointing.

    If everything worked out, you can start playing! For example, let's build a Fibonacci sequence. By default, we already have one table, in column X we do Fill Column With -> Row Numbers, in column Y we select Set Column Values ​​and we will enter a small program there, as shown in the figure. Do not forget to uncheck Use muParser. Unfortunately, it is active by default, which wildly infuriates.

    t = currentTable ()
    t.setCell (2,1,1)
    t.setCell (2,2,1)
    for in range (3,10):
       t.setCell (2, i, t.cell (2, i-1) + t.cell (2, i-2)

    Hooray, in column Y we got 10 Fibonacci numbers. But it was, so to speak, a test of the pen and checking that scripting was working. It is clear that each time writing a function is not very convenient, and the number of numbers is hardcoded. Therefore, we will create a function with blackjack and ... . We go to ~ / .qtiplot and create a file there, for example, qtimyfunc.py with the following contents (yes, I know that recursion is a lamer, but it's just an illustration): And add the line import_to_global ("qtimyfunc", None, to the qtiplotrc.py file) True). Restart as qtiplot and now our function will appear in the drop-down list of functions. Since this is a full-fledged Python program, you can cram everything there, from simple recursion to calculating the trajectory of a space ship.


    import qti, math

    #global fib

    def fib(n):

            "Calculates fibonacci numbers"

            if n == 0:

                    return 0

            elif n == 1:

                    return 1


                    return fib(n-1) + fib(n-2)

    But laziness does not stand still. Each time, fill out a column, enter a function, press a button depressingly a little less than completely. Therefore, we will write a script that will create a plate, fill it in and plot a chart. Let’s digress from Fibonacci, suppose we have some experimental data that are noisy and we need to construct the approximation and we know that in theory the data should have a quadratic law.

    We write the following script: The script uses the Qtiplot Python API , it is very simple and well-documented. To start it we execute a command from the console. Naturally, myscript.py should be in scope. The result of script execution will be, pleasing to the eye, the picture:

    import sys

    import qtimyfunc

    import random


    t = newTable("Data", 20, 2)

    t.setColName(1, "x")

    t.setColumnRole(1, Table.X)

    t.setColName(2, "y")

    t.setColumnRole(2, Table.Y)

    for i in range(1, 20):



    g = plot(t, t.colName(2), 1).activeLayer()

    f = PolynomialFit(g, "Data" + "_" + t.colName(2), 2, True)


    $ qtiplot -x myscript.py

    In addition to the ability to call scripts from the console, Qtiplot can add a script launch to any menu item or hang on the toolbar button. Thus, the possibilities of customizing the program are practically unlimited, you can create your own actions and call them with one click of the mouse. This is done in the Scripting menu. And it will turn out something like this:

    It should be noted that the program is constantly evolving, new features are being added, the API is expanding, and the interface is improving. Unfortunately, few people know about the program now, I hope this article will help its distribution. The program also has a forum where all sorts of useful additions are laid out on python.

    Also popular now: