Posted on Sun 26 February 2012

Plotting with julia

Maybe you've already heard it: There's a new language on the block - Julia. She seems to be a hot contender for the new standard scientific computing language, maybe also replacing R for statistical analysis.

Julia is a high-level, high-performance dynamic programming language for technical computing, with syntax that is familiar to users of other technical computing environments. It provides a sophisticated compiler, distributed parallel execution, numerical accuracy, and an extensive mathematical function library.

Of course, it's a very young language, so they standard library is quite small right now. For example, you can also plot to the webinterface, not to real image files. That wasn't enough for me, so I set out to create my own small plotting interface.

Like the rest of Julia, it's very easy to use, just a few characters to plot something:

1
plot(x -> sin(x), 0, 2pi, "sample.png")

If you wanted a more elaborate plot, you'd do this:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
# create new plot of size 800x300
pl = Plot(800, 300)

# add functions
add(pl, x -> sin(x))
# optionally choose a color
add(pl, x -> 2*cos(x), "b")

# export to a file
paint(pl, "myplot.png")

An example plot

It's based on [cached]MathGL, an awesome plotting library for C/C++. As usual, [cached]the source is on GitHub, so feel free to contribute :)

Tags: programming, graphics

© Julian Schrittwieser. Built using Pelican. Theme by Giulio Fidente on github. .