Plot not defined with Julia

2019-04-05 07:26发布

I compiled Julia 0.1 from the source code on my Ubuntu 12.04. It is my first time try with Julia actually.

The compilation got through to the end with no problem but some warnings.

When I try to execute the plot command , here comes the problem,

    julia> plot(x->sin(x^2)/x, -2pi,2pi)
    ERROR: plot not defined

Did the compilation go wrong somewhere or Do I have to install extra package to plot in Julia? Thanks

标签: plot julia
4条回答
可以哭但决不认输i
2楼-- · 2019-04-05 07:32

OK I found the solution myself,

Julia uses a web REPL to provide some basic graphics capabilities. Just have to follow the steps here:

https://github.com/JuliaLang/julia#web-repl

Julian Schrittwieser also has a library based on MathGL:

http://www.furidamu.org/blog/2012/02/26/plotting-with-julia/

I am not sure whether it is still under maintenance by the author.

查看更多
Lonely孤独者°
3楼-- · 2019-04-05 07:36

The web-based graphics are outdated and unmaintained (though there's work in progress to get the next generation of web graphics working). Plotting alternatives include the Winston or Gadfly packages at https://github.com/nolta/Winston.jl and https://github.com/dcjones/Gadfly.jl which you can install simply using the Pkg.add("Winston") (or Pkg.add("Gadfly") commands). For documentation and usage examples please refer to the linked repositories.

查看更多
相关推荐>>
4楼-- · 2019-04-05 07:45

As of right now (a few years passed since the question was asked so the ecosystem has matured), the package I would suggest for easy quick plots would be Gadfly, with some use of PyPlot for publication quality graphs that require a lot of control.

To install, just type

Pkg.add("Gadfly")

in a Julia command line, and to use, type:

using Gadfly
plot([sin, cos], 0, 25)

PyPlot is still the preferred plotting option for when you want a lot of control over your graphs, but it is a wrapper for a Python library and is slightly less user-friendly. It also requires a working python install on your system.

查看更多
Emotional °昔
5楼-- · 2019-04-05 07:50

For MATLAB-style plotting under Julia, type once

Pkg.add("PyPlot")

to install the PyPlot package, which gives you access to Python's matplotlib library. Then try e.g.

using PyPlot
x = -2pi:0.1:2pi;
plot(x, sin(x.^2)./x);
查看更多
登录 后发表回答