Makie error: scatter! not defined

Can anyone help? I get an error of:
LoadError: UndefVarError: scatter! not defined

when I run this code:

using Makie

f(x,y) = cos(x)*cos(y)*sqrt(x^2 + y^2)

x = range(-5, length = 100, stop = 5)
y = range(-5, length = 100, stop = 5)
z = f.(x, y')

Makie.surface(x, y, z, colormap = :viridis, shading = false)
scatter!([1], [1], [4], markersize = 1.0)

(is this happening because of inconsistency of old codes? why some syntax are not working like linspaces, etc?)

You only need to import Makie if you are writing library code that expects to use any of the Makie backends. When you just want to make plots, you need to import the appropriate backend. If you are running in a terminal or VSCode, that is probably GLMakie. If you want to make graphics for a paper, that is probably CairoMakie, if you are in a notebook probably WGLMakie.

Are you sure that’s what you’re seeing? When I run your code I get:

julia> Makie.surface(x, y, z, colormap = :viridis, shading = false)
Error showing value of type Makie.FigureAxisPlot:
ERROR: No backend available!
Make sure to also `import/using` a backend (GLMakie, CairoMakie, WGLMakie).

As expected, as one shouldn’t use Makie directly. When I do so I get:

julia> using CairoMakie

julia> Makie.surface(x, y, z, colormap = :viridis, shading = false)
Scene (800px, 600px):
  0 Plots
  1 Child Scene:
    â”” Scene (800px, 600px)

julia> scatter!([1], [1], [4], markersize = 1.0)
Scatter{Tuple{Vector{Point{3, Float32}}}}

So you likely imported some other package that exports scatter! and have a name conflict.

Make sure to run any MWE you post here in a fresh session before posting to see if there’s any hidden state in your current session causing your problem.

Hi @nilshg ,

Aside from technical question…

I was reading the GLMakie repo, since I am newbie to Julia. I do not understand what is the meaning of can't use Makie directly.

and
Cairo and WebGL are backend for Makie

why Makie need backend ? Is it for plotting / rendering purpose? Can one use Plots with Makie to plot a graph?

Makie.jl only defines what plot objects are, it doesn’t know how to make images or vector graphics out of that information. The backends, CairoMakie, GLMakie, and WGLMakie implement different ways to turn the plot objects into rendered graphics, for example using the Cairo C library, OpenGL or WebGL.

You cannot use Plots.jl with Makie as nobody has written a working backend for Plots.jl that uses Makie.

1 Like

Thanks for the explanation @jules , it is better to get an answer from expert who understand than just googling.