Plots Julia Contour

Posted on by admin

Julia Plots

Plotting options in Julia I PyPlot(our recommendation) JuliaBoxsupports PyPlot PyPlotcan be made to run locally (but it’s not straightforward) I other options (not recommended): Plots, Gadfly. Using Plots x = 1:10; y = rand(10); # These are the plotting data plot(x, y) The plot is displayed in a plot pane, a stand-alone window or the browser, depending on the environment and backend (see below). In Plots.jl, every column is a series, i.e. A set of related points which form lines, surfaces, or other plotting primitives. However this gives a plot without any contour curves on it, with a message saying 'Arrays have incorrect length or dimension.' But the contour function seems to accept, as in the link above, arbitrary x, y arrays and a function of x, y, and returns a contour plot. This should not give rise to any dimension problems.

Plots

Plots are used to visualize data in a graphical representation. In Julia, Plots can be drawn in different ways.

In this tutorial, we will learn how to draw a Plot in Julia using Plots.jl package.

Install Plots.jl

Plots

You have to install Plots.jl package in Julia if you have already not installed.

To install Plots.jl, add “Plots” package using Pkg as shown below:

For the first time, Julia itself compiles the Plots package for you.

Example – 2D Plot in Julia

In this example, we shall draw a 2D plot in Julia.

Plots package supports multiple backend libraries that actually do the drawing which implement the same API ofcourse. In this example, we will use GR module. GR is essentially based on an implementation of a Graphical Kernel System (GKS) and OpenGL.

script.jl

Output

Julia Plots Figure Size

This is just a basic 2D plot. You can add much more information to this plot.

Adding Another Plot to the existing Plot

Let us now add small circles at the points.

We shall use scatter() function. Using ! in scatter!() makes scatter! a mutating function, indicating that the scattered points will be added onto the pre-existing plot.

script.jl

Julia Plots Legend

Output

Writing X-label and Y-label

Let us complete this plot with all the basic information. We will add labels to X and Y axes using xlabel() and ylabel() functions.

script.jl

X and Y labels are added to the plot.

Giving our Plot a Title

To give a title to the plot, use the function title().

script.jl

Conclusion

In this Julia Tutorial, we learned about Julia Plots.