gjkerns / ob-julia

36 stars 25 forks source link

[question] how to generate image result in Org-mode with ob-julia #4

Closed stardiviner closed 8 years ago

stardiviner commented 8 years ago

I use Gadfly graphics library.

And with a julia code block like this:

#+BEGIN_SRC julia
using Gadfly

myplot = plot(x=rand(10), y=rand(10))

draw(SVG("myplot.svg", 4inch, 3inch), myplot)
#+END_SRC

I tried different header arguments like :results graphics, or without header arguments. Both did not work. How to do this?

larrasket commented 1 year ago

@stardiviner have you reached a solution?

stardiviner commented 1 year ago

@larrasket Try this:

#+begin_src julia :results graphics file :file "data/images/result-inline-image.png"
p(x) = 4*x - 5*x^3 + x^5;
xs = linspace(-2.25, 2.25); ys = map(p, xs);

using Gadfly

# fig1 = plot(x = xs, y = ys, Geom.line)
# draw(SVG("gadfly.svg", 4inch, 2inch), fig1)

fig2 = plot([p, x->2*x^2], -2.25, 2.25)
draw(PNG("data/images/result-inline-image.png", 6inch, 3inch), fig2)
#+end_src