-1

I'm trying to plot a 3D plot from an array p. However, I get an error. What's the reason for it and how can I overcome this?

Code

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')
x=p[:, 0]
y=p[:, 1],
z=p[:, 2], 
ax.plot(x, y, z)
ax.legend()
plt.show()

Error

Traceback (most recent call last):

  File "<ipython-input-51-6e9ef1b4241b>", line 11, in <module>
    ax.plot(x, y, z)

  File "C:\Users\Ramdayal\Anaconda3\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 1537, in plot
    lines = Axes.plot(self, xs, ys, *args[argsi:], **kwargs)

  File "C:\Users\Ramdayal\Anaconda3\lib\site-packages\matplotlib\__init__.py", line 1897, in inner
    return func(ax, *args, **kwargs)

  File "C:\Users\Ramdayal\Anaconda3\lib\site-packages\matplotlib\axes\_axes.py", line 1406, in plot
    for line in self._get_lines(*args, **kwargs):

  File "C:\Users\Ramdayal\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 407, in _grab_next_args
    for seg in self._plot_args(remaining, kwargs):

  File "C:\Users\Ramdayal\Anaconda3\lib\site-packages\matplotlib\axes\_base.py", line 360, in _plot_args
    raise ValueError('third arg must be a format string')

ValueError: third arg must be a format string
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
  • What is your actual question? And what have you tried so far? The value error you are getting should be a good hint at what's going wrong. – Andrew Guy Jun 23 '17 at 03:00
  • Questions seeking debugging help ("**why isn't this code working?**") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it **in the question itself**. Questions without a **clear problem statement** are not useful to other readers. See: [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – Andrew Guy Jun 23 '17 at 03:02
  • I am getting ValueError: third arg must be a format string, How can I solve? – user8174493 Jun 23 '17 at 03:05
  • Please read my second comment. The code provided is not a minimal, complete and verifiable example. When I run it, I get `NameError: name 'p' is not defined`. Can you edit you question to provide a clear explanation of what you are trying to achieve? – Andrew Guy Jun 23 '17 at 03:10
  • See also: https://stackoverflow.com/help/how-to-ask You will get much more help if you put a bit more effort into writing your questions. – Andrew Guy Jun 23 '17 at 03:17

1 Answers1

0

You define your y and z as tuples: y = something, would result in (something, ), while you really want to have y = something without comma.

x=p[:, 0]
y=p[:, 1]  #remove comma
z=p[:, 2]  #remove comma
ax.plot(x, y, z)
ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712