# Plot, surface! with MethodError: no method matching length(::ColorGradient)

**URL:** <https://discourse.julialang.org/t/plot-surface-with-methoderror-no-method-matching-length-colorgradient/14011>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [August 24, 2018, 7:48pm UTC](https://discourse.julialang.org/t/plot-surface-with-methoderror-no-method-matching-length-colorgradient/14011 "2018-08-24T19:48:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)\
**Post date:** [August 24, 2018, 7:48pm UTC](https://discourse.julialang.org/t/plot-surface-with-methoderror-no-method-matching-length-colorgradient/14011/1 "2018-08-24T19:48:20Z")

</div>

```julia
using Plots

x_min, x_max = -5, 5
y_min, y_max = -5, 5

α, β = 0.2, 0.1

# Axes
gs = 3
z = range(x_min, stop = x_max, length = gs)
x = zeros(gs)
y = zeros(gs)
plot(x, y, z, color=:black, linewidth=2, alpha=0.5, label="", legend=false)
plot!(z, x, y, color=:black, linewidth=2, alpha=0.5, label="")
plot!(y, z, x, color=:black, linewidth=2, alpha=0.5, label="")

# Fixed linear function, to generate a plane
f(x, y) = α .* x + β .* y

# Vector locations, by coordinate
x_coords = [3, 3]
y_coords = [4, -4]
z = f(x_coords, y_coords)

# Lines to vectors
n = 2
x_vec = zeros(n, n)
y_vec = zeros(n, n)
z_vec = zeros(n, n)
labels = []

for i ∈ 1:n
    x_vec[:, i] = [0; x_coords[i]]
    y_vec[:, i] = [0; y_coords[i]]
    z_vec[:, i] = [0; f(x_coords[i], y_coords[i])]
    lab = string("a", i)
    push!(labels, lab)
end

plot!(x_vec, y_vec, z_vec, color=[:blue :red], linewidth=1.5,
    alpha=0.6, label=labels)
# Draw the plane
grid_size = 20
xr2 = range(x_min, stop = x_max, length = grid_size)
yr2 = range(y_min, stop = y_max, length = grid_size)
z2 = Matrix{Float64}(undef, grid_size, grid_size)
for i ∈ eachindex(grid_size)
    for j ∈ eachindex(grid_size)
        z2[j, i] = f(xr2[i], yr2[j])
    end
end
surface!(xr2, yr2, z2, cbar=false, alpha=0.2, fill=:blues,
    xlims=(x_min, x_max), ylims=(x_min, x_max),
    zlims=(x_min, x_max), xticks=[0], yticks=[0],
    zticks=[0])

```

(source: QuantEcon Julia Lectures: linearalgebra with Julia `v"1.0.0"`)

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [August 24, 2018, 8:48pm UTC](https://discourse.julialang.org/t/plot-surface-with-methoderror-no-method-matching-length-colorgradient/14011/2 "2018-08-24T20:48:20Z")

</div>

Resolved in [https://github.com/JuliaPlots/Plots.jl/issues/1690](https://github.com/JuliaPlots/Plots.jl/issues/1690) , thanks for opening an issue!
