This is great, thanks! Any idea how to change the color of the grid lines when doing st=:wireframe? I’ve tried every single color keyword argument/alias I can find in the docs and none of them work! Or, when using st=:surface do you know how to change the alpha? Again, I’ve tried all the alpha-related kwargs and none seem to do the trick.
I was able to hack together something that looks decent. Below is the code as well as the output for some data I’m working with:
x = 0:maximum(X)
y = 0:(maximum(Y)/length(x))+1:maximum(Y) # because x and y are of different lengths
z = [pdf(mvnorm, [i, j]) for i in x, j in y]
pyplot()
plot(x, y, z, linetype=:surface, legend=false, color=:blues)
plot!(x, y, z, linetype=:wireframe, legend=false, color=:black, width=0.1)
Looks nice. wireframe color should follow the linecolor keyword. alpha for surface isn’t implemented
BTW no need to call collect all the time (and you can delete the first assignment to y).
Just a warning/note about x-y ordering when creating the Z grid: if you’re plotting as a contour/heatmap, then you’ll want to reverse the for x in X, y in Y ordering to be for y in Y, x in X so that the grid maps to the x-y axes correctly. This is subtle, as it will not always present itself as a problem depending on the parameters of the MvNormal.
Here’s an example plotting a bivariate normal distribution as filled contours:
using Distributions
using Plots
μ = [0, 0]
Σ = [1 0.9;
0.9 10]
p = MvNormal(μ, Σ)
X = range(-8, 8, length=100)
Y = range(-8, 8, length=100)
Z = [pdf(p, [x,y]) for y in Y, x in X] # Note x-y "for" ordering
contourf(X, Y, Z, color=:viridis)
To avoid Z altogether, you can pass a function f to handle calculating the z-values:
f(x,y) = pdf(p, [x,y])
contourf(X, Y, f, color=:viridis)