user3165619
user3165619

Reputation: 9

Why do i have this error with matplotlib

I'm trying to make a scatterplot of some data in matplotlib using:

ax.scatter(X, Y, Z, c='r', marker='0')

However, I'm getting the error below:

 Traceback (most recent call last):
    File "C:\Users\K\Desktop\3d", line 11, in <module>
    ax.scatter(X, Y, Z, c='r', marker='0')
    File "C:\Python27\ArcGIS10.1\lib\site-packages\mpl_toolkits\mplot3d\axes3d.py", line 2180, in scatter
    patches = Axes.scatter(self, xs, ys, s=s, c=c, *args, **kwargs)
    File "C:\Python27\ArcGIS10.1\lib\site-packages\matplotlib\axes.py", line 6296, in scatter
    marker_obj = mmarkers.MarkerStyle(marker)
    File "C:\Python27\ArcGIS10.1\lib\site-packages\matplotlib\markers.py", line 162, in __init__
    self.set_marker(marker)
    File "C:\Python27\ArcGIS10.1\lib\site-packages\matplotlib\markers.py", line 233, in set_marker
    Path(marker)
    File "C:\Python27\ArcGIS10.1\lib\site-packages\matplotlib\path.py", line 147, in __init__
    assert vertices.ndim == 2
    AssertionError

What am I missing? I can't see anything wrong.

Upvotes: 0

Views: 699

Answers (1)

Joe Kington
Joe Kington

Reputation: 284562

Your problem appears to be due to mistaking 0 for o.

Try ax.scatter(X, Y, Z, c='r', marker='o') (instead of marker='0').

If you pass in a maker that isn't one of matplotlib's marker codes, it assumes that you're passing in an array of vertices that can be converted into a path that can be used as a marker. Thus the somewhat cryptic error you're receiving.

If you want a literal 0 as the marker, use marker='$0$'. The dollar signs indicate a latex-formatted string, which matplotlib will use as the marker.

Upvotes: 3

Related Questions