Meshgrid function in Julia

You don’t need a meshgrid for contour plotting with PyPlot — you can pass 1d arrays for the axes and it knows how to broadcast them, and you write 2d functions of the axes variables by broadcast operations as well:

using PyPlot
x = range(0,2,length=100)'  # note ': this is a row vector
y = range(0,4,length=200)
z = @. sin(x) * cos(y)  # broadcasts to 2d array
contour(x, y, z)

image

16 Likes