Julia Quick Start

Install Julia here . You’ll copy and paste a command into your terminal or command line, and that will install it! On a mac at the end there will be instructions to copy paste one more line into your terminal after installation. Make sure to do that!

On older systems this might not work. In which case download Julia here . If you have a Mac, you’ll want to look up which generation you have and install the correct version via the corresponding .dmg file.

Open the Julia application. You should see a startup banner similar to this:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version x.y.z (YYYY-MM-DD)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia>

Try typing in 2+2 and hitting enter.

Install Visual Studio Code (VS Code)

After confirming Julia runs, download and install VS Code. On mac remember to drag the application into your applications folder.

  • Open VS Code.
  • Click on the Extensions icon in the Activity Bar on the side of the window. It looks like four squares forming a larger square, with the top-right square slightly detached.
  • Search for “Julia” in the search bar.
  • Find the extension named Julia published by julialang and click Install.

Create and Run Your First Julia File

  • Create a new file named HelloJulia.jl.
  • Open this file in VS Code.
  • Paste the following code into the file:
τ = pi*2 #make this symbol by typing \tau then hitting tab
print("The first digits of tau are $τ")
The first digits of tau are 6.283185307179586
  • Run the code by clicking the trinagluar play icon in the top-right corner of the editor.

I like to use Visual Studio code for running these files because it has can show all the current variable values in the workspace menu. On the left bar click on the three circles that make up the Julia logo and you’ll see the workspace. Trying creating some variables, and look at how the workspace is populated.

Manage Julia Packages

In the VS Code terminal panel where you saw the output, you should see the Julia prompt julia>. Press the ] key. The prompt will change to indicate you are in package mode. To exit and return to the standard julia mode press the Backspace key.

While in Package mode, type the following command and press Enter:

add GLMakie CairoMakie DataFrames

Then wait for installation, this can take awhile.

Differentiate and graph data

Now you can modify your HelloJulia.jl script (or create a new one) to use these packages. Here’s an example that calculates the derivative of some data (a sine wave), then creates a simple plot using Makie and if you uncomments ome code, saves it as a PDF:

using GLMakie

x = 0:0.1:2pi #create an x-range
y = sin.(x) #create some y-data, a sin wave.
∂y∂x = diff(y) ./ diff(x) #Calculate the derivative, cos!

# Create the plot figure and axis
fig = Figure(size = (400, 400))
ax = Axis(fig[1, 1], xlabel = "X [um]", ylabel = "Y [Pa]")

# Plot the lines
lines!(ax, x, y, label = "y=sin(x)", color = :blue, linewidth = 2)
lines!(ax, x[1:end-1], ∂y∂x, label = "∂y/∂x", color = :red, linewidth = 2)

axislegend(ax) # Add a legend

# Show the plot in an interactive window
GLMakie.activate!() 
fig #or display(fig)

#These hash marks are comments
#= you can create a comment block like this
#Get rid of this comment block, to save the figure.
using CairoMakie
 Save the plot as a PDF
CairoMakie.activate!()
save("plot.pdf", fig)
=#

On some MacOS systems, the plot will appear in a terminal window behind everything else, so you will have to alt-tab to find it.

Some resources

MIT has a Julia Course, with a terrific YouTube series that teaches both Julia and some great foundations of programming for image analysis.

Julia has a dedicated YouTube Channel where you can see what people in the community are up to at various Julia conferences.