Plotting surface with plots and pyplot

I am trying to plot a 3D object with using Plots or PyPlot with the command surface. When I utilize Plots and surface(x,y,z) where x,y,z are three vectors with the same size, I get the message:
*** IDENTICAL DATA POINTS.
NDP = 100 IP1 = 1 IP2 = 2 XD=0 YD=0
ERROR DETECTED IN ROUTINE IDTANG.
libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
X Error of failed request: BadMatch (invalid parameter attributes)
Major opcode of failed request: 148 (GLX)
Minor opcode of failed request: 26 (X_GLXMakeContextCurrent)
Serial number of failed request: 27
Current serial number in output stream: 27

Also, when I use PyPlot and surf command, I get the message:
PyError ($(Expr(:escape, :(ccall(#= /home/neda/.julia/packages/PyCall/ygXW2/src/pyfncall.jl:43 =# @pysym(:PyObject_Call), PyPtr, (PyPtr, PyPtr, PyPtr), o, pyargsptr, kw))))) <class ‘RuntimeError’>
RuntimeError(‘Error in qhull Delaunay triangulation calculation: singular input data (exitcode=2); use python verbose option (-v) to see original qhull error.’)
File “/home/neda/.julia/conda/3/lib/python3.10/site-packages/mpl_toolkits/mplot3d/axes3d.py”, line 1770, in plot_trisurf
Triangulation.get_from_args_and_kwargs(*args, **kwargs)
File “/home/neda/.julia/conda/3/lib/python3.10/site-packages/matplotlib/tri/triangulation.py”, line 161, in get_from_args_and_kwargs
triangulation = Triangulation(x, y, triangles, mask)
File “/home/neda/.julia/conda/3/lib/python3.10/site-packages/matplotlib/tri/triangulation.py”, line 58, in init
self.triangles, self._neighbors = _qhull.delaunay(x, y)

Please let me know that does anyone know the problem?
Thank you so much in advance.

There are two points with the same X-Y coordinates, they must all be different.

Thank you Rafael for the reply. I checked the code and tried it with different x and y as the input for surface and the error is:
surface(x,y,z)
libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
X Error: BadMatch
Request Major code 148 (GLX)
Request Minor code 26 ()
Error Serial #27
Current Serial #27

I tried the command surface in a very simple code:

using LinearAlgebra

using Plots; plotyjs()

r = collect(Float16, range(0, length=100, stop=1));

theta = collect(Float16, range(0, length=100, stop=2*pi));

len =100

a = zeros(len); x = zeros(len); y = zeros(len)

A = fill(zeros(2), len)

for i in 1:len

x[i] = r[i]*cos(theta[i])

y[i] = r[i]*sin(theta[i])

end

z = zeros(Float16, len)

for i in 1:len

z[i] = x[i]^2 + y[i]^2

end

surface(x,y,z)

OK, now it seems to be a new problem and I have no idea.

NB:

  • Here, your code runs fine and a surface can be displayed with gr() backend.
  • If I am not mistaken, plotlyjs() surface() expects a regular x-y mesh of points
  • use triple backticks around your code:
    ```
    type the code here
    ```

“”
‘’’ using LinearAlgebra
using Plots; gr()

r = collect(Float16, range(0, length=100, stop=1));
theta = collect(Float16, range(0, length=100, stop=2*pi));
len =100
a = zeros(len); x = zeros(len); y = zeros(len)

for i in 1:len
x[i] = r[i]*cos(theta[i])
y[i] = r[i]*sin(theta[i])
end
z = zeros(Float16, len)
for i in 1:len
z[i] = x[i]^2 + y[i]^2
end
surface(x,y,z)‘’’

I tried the gr() backend as you see in the above code. The error is the same as the before: libGL error: MESA-LOADER: failed to open swrast: /usr/lib/dri/swrast_dri.so: cannot open shared object file: No such file or directory (search paths /usr/lib/x86_64-linux-gnu/dri:$${ORIGIN}/dri:/usr/lib/dri, suffix _dri)
libGL error: failed to load driver: swrast
X Error: BadMatch
Request Major code 148 (GLX)
Request Minor code 26 ()
Error Serial #27
Current Serial #27

From you code it seems that you intend to plot a paraboloid of equation z= x^2+y^2, using a parameterization, of parameters r and theta. You can avoid using for loops, as follows:

using Plots; plotlyjs()
r = collect(Float16, range(0, 1, length=100));
theta = collect(Float16, range(0, 2*pi, length=100));
x = r .* cos.(theta)'  #outer product of the column r with the row, cos.(theta)'
y = r .*sin.(theta)'
z = r.^2 .* ones(size(theta))'   #x^2=y^2=r^2
surface(x,y,z)

In Linear Algebra the outer product is the product of a column with a row vector, and the result is a Matrix.
Check by printing:

print(size(x), size(y), size(z))

Thanks a lot