forked from gizmaa/Julia_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpyplot_surfaceplot.jl
More file actions
52 lines (44 loc) · 1.12 KB
/
pyplot_surfaceplot.jl
File metadata and controls
52 lines (44 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# pyplot_surfaceplot.jl
#
# Surface Plot demonstration
#
# Daniel Høegh (https://gist.github.com/dhoegh)
# Julia 1.1.0
# 09.12.2014
# Last Edit: 10.05.19
# Reference: https://groups.google.com/d/msg/julia-users/eVtZdp3htTM/TJOt3exCxKgJ
using PyPlot
using Distributions
using LinearAlgebra
using3D() # Needed to create a 3D subplot
###################
## Create Data ##
###################
n = 100
x = range(-3,stop=3,length=n)
y = range(-3,stop=3,length=n)
xgrid = repeat(x',n,1)
ygrid = repeat(y,1,n)
z = zeros(n,n)
for i in 1:n
for j in 1:n
z[i:i,j:j] .= pdf(MvNormal(Matrix(1.0I,2,2)),[x[i];y[j]])
end
end
############
## Plot ##
############
fig = figure("pyplot_surfaceplot",figsize=(10,10))
ax = fig.add_subplot(2,1,1,projection="3d")
plot_surface(xgrid, ygrid, z, rstride=2,edgecolors="k", cstride=2, cmap=ColorMap("gray"), alpha=0.8, linewidth=0.25)
xlabel("X")
ylabel("Y")
PyPlot.title("Surface Plot")
subplot(212)
ax = fig.add_subplot(2,1,2)
cp = contour(xgrid, ygrid, z, colors="black", linewidth=2.0)
ax.clabel(cp, inline=1, fontsize=10)
xlabel("X")
ylabel("Y")
PyPlot.title("Contour Plot")
tight_layout()