PyPlot error, plot 3D line

question

#1

The error in the following code.
ax.plot(xs, ys, zs) # no method found
Could anyone give me some help? Thanks!

using PyPlot; const plt = PyPlot
xs = Float64[]
ys = Float64[]
zs = Float64[] 
# initialize xs, ys, zs
...

# show 3D line
fig = plt.figure()
ax = fig[:add_subplot](111, projection="3d")
ax.plot(xs, ys, zs)   # error, "type PyObject has no field plot "

#2

The aforementioned code is from the following python example. Can anyone convert the following code from Python to Julia? Thanks

import matplotlib as mpl
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import matplotlib.pyplot as plt

mpl.rcParams['legend.fontsize'] = 10

fig = plt.figure()
ax = fig.gca(projection='3d')
theta = np.linspace(-4 * np.pi, 4 * np.pi, 100)
z = np.linspace(-2, 2, 100)
r = z**2 + 1
x = r * np.sin(theta)
y = r * np.cos(theta)
ax.plot(x, y, z, label='parametric curve')
ax.legend()

plt.show()

#3

Shouldn’t that be plot3d instead of plot?


#4

You need ax[:plot]


#5

It is solved. The code is as following.
can use keys( obj ) to show the attributes and member functions of the PyObject.

using PyPlot; const plt = PyPlot

theta = collect( linspace( -4π, 4π, 100 ) )
z = collect( linspace(-2, 2, 100) )
r = z.^2 + 1;
x = r .* sin(theta)
y = r .* cos(theta)

fig = plt.figure()
ax = fig[:add_subplot](111, projection="3d")    
ax[:plot](x, y, z)   # PyObject, use obj[:function_name] to call the member function 

image