Draw graphs in the programming language Julia

I tried to build an environment to draw a graph with the programming language Julia. The PySide Package has been added. The sample program that displays the graph at the end of the sentence is attached to the PySide package of Julia. With some modifications (added PySide.app [: exec_]() to the last line). (If you have any bugs or comments, please contact https://twitter.com/akmiyoshi)

I have (later) posted the procedure for building an environment on Windows 7 </ del>. If you are interested, please stock.

My environment is Windows 7 Home Premium 64bit, but I installed the 32bit version of the program for all environment construction. If you follow this procedure, it will work on both 32bit and 64bit versions of Windows OS (XP SP2 or later).

[Addition] Steps 4, 6 and 11 have been added to 2014/07/04. If you have seen this article before 2014/07/04 and built the environment, please follow steps 4, 6 and 11. Thank you.

pyqtgraph.gif

1. Install Python 2.7.7 (32bit).

2014-0701-1224.png

2. Install numpy (32bit).

3. Install scipy (32bit).

4. Install matplotlib. (Added on 2014/07/04)

5. Install pip (a tool for installing / managing Python packages).

C:\Users\root>c:\get-pip.py

6. Install the matplotlib dependent libraries. (Added on 2014/07/04)

C:\Users\root>cd \Python27\Scripts

C:\Users\root>cd \Python27\Scripts
C:\Python27\Scripts>pip install -U python-dateutil
C:\Python27\Scripts>pip install -U pyparsing

7. Install PySide.

C:\Users\root>cd \Python27\Scripts
C:\Python27\Scripts>pip install -U PySide

8. Install PyOpenGL.

C:\Users\root>cd \Python27\Scripts
C:\Python27\Scripts>pip install -U PyOpenGL

9. Install PyQtGraph (32bit).

10. Install Julia (32bit).

11. Add the PyPlot package to Julia. (Added on 2014/07/04)

julia> Pkg.add("PyPlot")

12. Add the PySide package to Julia.

julia> Pkg.add("PySide")

13. Run the sample program.

pyqtgraph.jl


## using the PyQtGraph submodule
## Examples from pyqtgraphs plotting.py
## translated into julia style

using PySide
reload(Pkg.dir("PySide", "src", "pyqtgraph.jl"))
using PyQtGraph
using PyCall


w = Widget()
lyt = VBoxLayout(w)
setLayout(w, lyt)

## Graphics Layout Widget make grid of plot devices
win = GraphicsLayoutWidget(w)
addWidget(lyt, win)
set_size(w, 800, 600)

raise(w)

## addPlot adds a plot device in next column over and returns a plot object
p1 = addPlot(win, title="Basic array plotting")
p1.plot(randn(100))

p2 = addPlot(win, title="Multiple curves")
p2.plot(randn(100), pen=(255,0,0))
p2.plot(randn(100) .+ 5, pen=(0, 255, 0))
p2.plot(randn(100) .+ 10, pen=(0,0,255))


p3 = addPlot(win, title="Drawing with points")
p3.plot(randn(100), pen=(200, 200, 200), symbolBrush=(255,0,0), symbolPen="w")

nextRow(win)

p4 = addPlot(win, title="Parametric, grid enabled")
p4.plot(sin(linspace(0, 2pi, 1000)), cos(linspace(0, 2pi, 1000)))
p4.showGrid()                   # defaults x=true, y=true

p5 = addPlot(win, title="Scatter plot, axis labels, log scale")
x = 1e-5 * rand(1000)
y = x*1000 .+ 0.005 * randn(1000)
y -= minimum(y).-1.0
mask = x .> 1e-15
x = x[mask]
y = y[mask]
p5.plot(x, y, pen=nothing, symbol="t", symbolPen=nothing, symbolSize=10, symbolBrush=(100, 100, 255, 50))
p5.setLabel("left", text="Y Axis", units="A")
p5.setLabel("bottom", text="Y Axis", units="s")
p5.setLogMode(x=true, y=false)



p6 = addPlot(win, title="Updating plot")

curve = p6.plot(pen="y")
data = randn(10000, 10)
ptr = 0
function update()
    global curve, data, ptr, p6
    qinvoke(curve, :setData, 1:10_000, data[:, 1 + ptr]) # had to fix this
    if ptr == 0
        p6.enableAutoRange("xy", false)  ## stop auto-scaling after the first data set is plotted
    end
    ptr = (ptr + 1) % 10
end


timer = QtCore[:QTimer]()
qconnect(timer, :timeout, update)
qinvoke(timer, :start, 50)


nextRow(win)


p7 = addPlot(win, title="Filled plot, axis disabled")
y = sin(linspace(0.0, 10, 1000)) .+ randn(1000)*0.1
p7.plot(y, fillLevel=-0.3, brush=(50,50,200,100))
p7.showAxis("bottom", show=false)



p8 = addPlot(win, title="Region Selection")

x2 = linspace(-100, 100, 1000)
data2 = sin(x2) ./ x2
p8.plot(data2, pen=(255,255,255,200))

## no special functions for LinearRegionItem
lr = pyqtgraph.(:LinearRegionItem)([400,700])
qinvoke(lr, :setZValue, -10)
p8.addItem(lr)

p9 = addPlot(win, title="zoom")
p9.plot(data2)

function updatePlot()
    p9.setXRange(lr[:getRegion]()...,padding=0)
end
function updateRegion()
    view_range = qinvoke(p9, [:getViewBox, :viewRange]) # 2x2 array
    x_range = Int[view_range[1,j] for j in 1:2]         # a vector, not just view_range[1,:]'
    lr[:setRegion](x_range)
end
qconnect(lr, :sigRegionChanged, updatePlot)
#qconnect(p9, :sigXRangeChanged, updateRegion) ## this is giving issues. Find out why.
updatePlot()

 #raise(w)

PySide.app[:exec_]()

Recommended Posts

Draw graphs in the programming language Julia
Draw graphs in Julia ... Leave the graphs to Python
The most sought after programming language in 2020
Programming language in "Hello World"
Programming to fight in the world ~ 5-1
Programming to fight in the world ~ 5-5,5-6
Programming to fight in the world 5-3
Activity record in the programming circle
Programming to fight in the world-Chapter 4
Switch the language displayed in Django 1.9
Start SQLite in a programming language
Programming to fight in the world ~ 5-2
A programming language that young people will need in the future
Looking back on 2016 in the Crystal language
Guidelines for reincarnating in the world of linux programming development (C / C ++ language)
Programming in python
Tools that fit in your hand (programming language)
I wrote the hexagonal architecture in go language
Draw a graph in Julia ... I tried a little analysis
Carefully understand the exponential distribution and draw in Python
Japan may be Galapagos in terms of programming language
A programming language that protects the people from NHK
Check if it is Unix in the scripting language
Carefully understand the Poisson distribution and draw in Python
Check if it is Unix in the scripting language
The programming language you want to be able to use
The story around the time acquisition API in programming languages
Qiita's popular programming language
Python programming in Excel
Draw graph in python
Output "Draw ferns programmatically" to the drawing process in Python
A note for embedding the scripting language in a bash script
I tried to illustrate the time and time in C language
I tried programming the chi-square test in Python and Java.
[Pyro] Statistical modeling by the stochastic programming language Pyro ① ~ What is Pyro ~
Explanation of CSV and implementation example in each programming language