Native Ijulia notebook example¶
Please count about 20 seconds to have Julia Kernel 0.3.x started, before launching the cell First use time, you may have to relaunch Julia kernel 5 times until it stops its 'timeout' errors
In [3]:
# Julia using matplotlib
using PyPlot
x = linspace(0, 2*pi, 1000); # use the julia linspace
y = sin(3 * x + 4 * cos(2 * x)); # use the numpy cosine and julia sine
subplots(figsize=(3,3))
plot(x, y, color="red", linewidth=2.0, linestyle="--")
ylabel("the y axis")
xlabel("the x axis")
title("a sinusoidally-modulated sinusoid")
Out[3]:
PyObject <matplotlib.text.Text object at 0x000000001236C780>
In [4]:
# Julia using matplotlib and numpy (and whatever you want)
using PyPlot
using PyCall
@pyimport matplotlib.pyplot as plt
@pyimport numpy as np
# Note how we mix numpy and julia:
t = linspace(0, 2*pi, 1000); # use the julia linspace
s = sin(3 * t + 4 * np.cos(2 * t)); # use the numpy cosine and julia sine
fig = plt.gcf() # **** WATCH THIS VARIABLE ****
plt.subplots(figsize=(3,3))
plt.plot(t, s, color="red", linewidth=2.0, linestyle="--")
Figure(PyObject <matplotlib.figure.Figure object at 0x00000000123633C8>)
Out[4]:
1-element Array{Any,1}:
PyObject <matplotlib.lines.Line2D object at 0x00000000123F32E8>
In [5]:
#MANDEL Mandelbrot set.
using PyPlot
mc = 301
x = linspace(-2.1, 0.6, mc)'
y = linspace(-1.1, 1.1, mc)
C = complex(repmat(x, mc), repmat(y, 1, mc))
Z_max = 1e6
it_max = 50
Z = C
for k in 1:it_max
Z = Z .^ 2 + C
end
subplots(figsize=(3,3))
contourf(x, y, (abs(Z) .< Z_max))
title("Figure 1.7 Mandelbrot Set")
Out[5]:
PyObject <matplotlib.text.Text object at 0x000000001240FA90>
In [6]:
#list of current Julia Packages: you can add more via Pkg.add("NameOfPackage")
Pkg.status()
6 required packages: - IJulia 0.1.16 - Interact 0.1.6 - PyCall 0.7.3 - PyPlot 1.5.1 - SymPy 0.2.23 - WinRPM 0.1.6 19 additional packages: - BinDeps 0.3.7 - Color 0.4.0 - Compat 0.2.12 - DataStructures 0.3.5 - Dates 0.3.2 - Docile 0.4.3 - FixedPointNumbers 0.0.6 - Graphics 0.1.0 - JSON 0.4.0 - LaTeXStrings 0.1.2 - LibExpat 0.0.6 - Nettle 0.1.7 - REPLCompletions 0.0.3 - Reactive 0.1.10 - Requires 0.1.1 - SHA 0.0.3 - URIParser 0.0.3 - ZMQ 0.1.16 - Zlib 0.1.7
In [ ]: