当我在pycharm
中运行脚本时,以下代码正常工作import pandas as pd
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.patches as mpatches
c1 = mpatches.Patch(color="green",label="No Traffic")
c2 = mpatches.Patch(color="red",label="Traffic")
df = predict_df.limit(100).toPandas()
colors = {0:"red",1:"green"}
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.scatter(df["avgSpeed"],df["vehicleCount"],df["avgMeasuredTime"],c=df["prediction"].apply(lambda x: colors[x]),s=100,marker="o")
ax.set_xlabel('avgMeasuredTime')
ax.set_ylabel('avgSpeed')
ax.set_zlabel('vehicleCount')
plt.title("BiKmeans Traffic Data")
plt.legend(handles=[c1,c2])
plt.show()
我已经使用pip安装了matplotlib,也基于一些类似的问题尝试安装为sudo apt-get install python-matplotlib 但是我在Zepplin中得到了同样的错误,
File "/home/benjamin/.local/lib/python2.7/site-packages/mpl_toolkits/mplot3d/axes3d.py", line 280, in <lambda>
key=lambda col: col.do_3d_projection(renderer), AttributeError: 'PathCollection' object has no attribute 'do_3d_projection'
matplotlib的版本是2.2.0