RHP
RHP

Reputation: 103

How to Plot Graphs in Julia 0.5?

I'm learning Julia by working through Chris Rackauckas' Introduction and I've come across a task that requires me to plot some data. I couldn't manage to get the Plots module to import so I tried a simple test:

using Plots
x = 1:10
y = 0.5*x + 3
plot(x, y)

When I first run this piece of code using the Juno IDE I get an error:

LoadError: LoadError: LoadError: syntax: unhandled expr (error #<julia: Main.Base.MethodError(f=FixedPointNumbers.#floattype(), args=(Main.FixedPointNumbers.FixedPoint{UInt8, 8},))>)
in include_from_node1(::String) at .\loading.jl:488 (repeats 2 times)
in eval(::Module, ::Any) at .\boot.jl:234
in require(::Symbol) at .\loading.jl:415
in include_string(::String, ::String) at .\loading.jl:441
in include_string(::Module, ::String, ::String) at 2

This refers to the using statement in my snippet. This error does not appear when I run from the REPL. The version info is as follows:

Julia Version 0.5.0
Commit 3c9d753 (2016-09-19 18:14 UTC)
Platform Info:
System: NT (x86_64-w64-mingw32)
CPU: Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
WORD_SIZE: 64
BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
LAPACK: libopenblas64_
LIBM: libopenlibm
LLVM: libLLVM-3.7.1 (ORCJIT, haswell)

I currently have version 0.10.3 of Plots installed.

Upvotes: 0

Views: 550

Answers (2)

RHP
RHP

Reputation: 103

To work with the Run File command using the Juno package in the Atom IDE the plot has to be assigned to a variable and passed to the display function.

using Plots
pyplot()
x = 1:100
y = 0.5*x + 10
println(y)
graph = plot(x, y)
display(graph)

This will display the graph in Juno's Plots window. In the comments Arda Aytekin suggested that pyplot(display=true) or graph = plot(x, y, display=true) could be used, which leads to the graph displaying in a separate pyplot window.

Upvotes: 2

Arda Aytekin
Arda Aytekin

Reputation: 1301

If you provide some version/platform information by sharing the output of versioninfo(), one can help you better.

For instance, the below excerpt

Pkg.add("Plots")
using Plots
plotly() # this backend is installed by default
x = 1:10
y = 0.5*x + 3
plot(x, y)

works well under

Julia Version 0.5.0
Commit 3c9d753* (2016-09-19 18:14 UTC)
Platform Info:
  System: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-3720QM CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (NO_LAPACK NO_LAPACKE NO_AFFINITY SANDYBRIDGE)
  LAPACK: liblapack
  LIBM: libm
  LLVM: libLLVM-3.7.1 (ORCJIT, ivybridge)

Maybe you should conisder Pkg.add("PyPlot") or a similar backend, and try it again later?

Upvotes: 2

Related Questions