plt.show()不显示3d散点图

问题描述 投票:0回答:1

社区,

我尝试通过在jupyter笔记本上使用matplotlib Axes3D创建3d散点图。但是,一旦执行“ plt.show()”,它就不会显示图像。

#pip install matplotlib
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
%matplotlib inline
fig = plt.figure()
ax =fig.add_subplot(111, projection = '3d')
x = dframe['CTR']
y = dframe['Clicks']
z = dframe['Avg. CPC']
ax.scatter(x, y, z, c='r', marker='o')
plt.show()
python matplotlib
1个回答
0
投票

您的代码可以像这样正常工作:

from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt

fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")

# dummy data (your actual data should go here)
x = [1, 2, 3, 4]
y = x
z = x
ax.scatter(x, y, z, c="r", marker="o")
plt.show()

这显示:

enter image description here

可能是您的数据有问题。另外,由于仍然使用plt.show(),因此可以删除%matplotlib inline行。

© www.soinside.com 2019 - 2024. All rights reserved.