Plotly is free for unlimited public use.

Sensitive data? Upgrade to a paid plan

Show Sidebar Hide Sidebar

# Contour Plots in Julia

How to make a contour plot in julia. Seven examples of contour plots of matrices with subplots, custom color-scales, and smoothing.

#### Basic Contour Plot

``````# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly

size = 100
x = linspace(-2*pi, 2*pi, size)
y = linspace(-2*pi, 2*pi, size)
z = rand(size, size)
for i = 1:size
for j = 1:size
r2 = (x(i)^2 + y(j)^2)
z(i,j) = sin(x(i))*cos(y(j))*sin(r2)/log(r2+1)

data = [
[
"z" => z,
"x" => x,
"y" => y,
"type" => "contour"
]
]
response = Plotly.plot(data, ["filename" => "simple-contour", "fileopt" => "overwrite"])
plot_url = response["url"]
``````

#### 2D Histogram Contour Plot with Histogram Subplots

``````# Learn about API authentication here: https://plot.ly/julia/getting-started
# Find your api_key here: https://plot.ly/settings/api

using Plotly

t = linspace(-1, 1.2, 2000)
x = t.^3+0.3*randn(2000)
y = t.^6+0.3*randn(2000)

trace1 = [
"x" => x,
"y" => y,
"mode" => "markers",
"name" => "points",
"marker" => [
"color" => "rgb(102,0,0)",
"size" => 2,
"opacity" => 0.4
],
"type" => "scatter"
]
trace2 = [
"x" => x,
"y" => y,
"name" => "density",
"ncontours" => 20,
"colorscale" => "Hot",
"reversescale" => true,
"showscale" => false,
"type" => "histogram2dcontour"
]
trace3 = [
"x" => x,
"name" => "x density",
"marker" => ["color" => "rgb(102,0,0)"],
"yaxis" => "y2",
"type" => "histogram"
]
trace4 = [
"y" => y,
"name" => "y density",
"marker" => ["color" => "rgb(102,0,0)"],
"xaxis" => "x2",
"type" => "histogram"
]
data = [trace1, trace2, trace3, trace4]
layout = [
"showlegend" => false,
"autosize" => false,
"width" => 600,
"height" => 550,
"xaxis" => [
"domain" => [0, 0.85],
"showgrid" => false,
"zeroline" => false
],
"yaxis" => [
"domain" => [0, 0.85],
"showgrid" => false,
"zeroline" => false
],
"margin" => ["t" => 50],
"hovermode" => "closest",
"bargap" => 0,
"xaxis2" => [
"domain" => [0.85, 1],
"showgrid" => false,
"zeroline" => false
],
"yaxis2" => [
"domain" => [0.85, 1],
"showgrid" => false,
"zeroline" => false
]
]
response = Plotly.plot(data, ["layout" => layout, "filename" => "2dhistogram-contour-subplots", "fileopt" => "overwrite"])
plot_url = response["url"]
``````
Still need help?