So I needed the help of matplotlib to visualize a few things in multivariable calculus, and one of them is a parametric curve. I don't really know python properly but I tried to understand the example on their website (https://matplotlib.org/stable/gallery/mplot3d/lines3d.html#sphx-glr-gallery-mplot3d-lines3d-py) and plot my own parametric curve.
import numpy as np
import matplotlib.pyplot as plt
ax = plt.figure().add_subplot(projection = '3d')
theta = np.linspace(0, 4*np.pi, 100)
x = np.cos(theta) + 3
y = 0
z = np.sin(theta)
now when I entered the above lines of code in IDLE there was no error, but then when I entered
ax.plot(x,y,z, label='Parametric curve')
It gave me the error :
Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
ax.plot(x,y,z, label = 'parametric curve')
File "C:\Users\Koustubh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1572, in plot
lines = super().plot(xs, ys, *args, **kwargs)
File "C:\Users\Koustubh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_axes.py", line 1605, in plot
lines = [*self._get_lines(*args, data=data, **kwargs)]
File "C:\Users\Koustubh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_base.py", line 315, in __call__
yield from self._plot_args(this, kwargs)
File "C:\Users\Koustubh\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0\LocalCache\local-packages\Python39\site-packages\matplotlib\axes\_base.py", line 501, in _plot_args
raise ValueError(f"x and y must have same first dimension, but "
ValueError: x and y must have same first dimension, but have shapes (100,) and (1,)
so can anyone help me with what did I do wrong here ? I am just trying really hard to visualize a parametric curve, but don't know any python yet.
Edit #1 : so I replaced y= 0
with y = np.sin(theta)-np.sin(theta)
and it worked fine and I got my plot. But why didn't defining y as zero normally work ?