importmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dimportnumpyasnp fig=plt.figure()ax=fig.add_subplot(111,projection='3d')x=np.random.standard_normal(100)y=np.random.standard_normal(100)z=np.random.standard_normal(100)scatter1=ax.scatter(x,y,z,color='c',label='how2...
2. 3D散点图(3D Scatter Plot) 用于可视化三维数据的散点图,通过在三维空间中绘制数据点来展示数据的分布。 代码语言:javascript 代码运行次数:0 运行 AI代码解释 import matplotlib.pyplot as plt import numpy as np # 数据准备 x = np.random.rand(100) # x轴数据 y = np.random.rand(100) # y轴数...
files, tool windows, actions, and settings.importmatplotlib.pyplotaspltimportnumpyasnpfrommpl_toolkits.mplot3dimportAxes3Ddefscatter():# 数据大小n=1024# 生成 n 个X值,符合标准正态分布X=np.random.normal(0,1,n)# 生成
ax.scatter(x, y, z) # 显示图表 plt.show() 在这个例子中,我们首先导入了必要的库,然后创建了50个随机数据点。接着,我们使用add_subplot函数创建了一个3D子图,并使用scatter函数绘制了散点图。最后,使用show函数显示图表。线图(Line Plot)在3D图中创建线图的方式与2D图类似。只需要将数据传递给plot函数即可...
from mpl_toolkits.mplot3d import Axes3D 然后使用下面的两种方式之一声明要创建三维子图: ax = fig.gca(projection='3d') ax = plt.subplot(111, projection='3d') 接下来就可以使用ax的plot()方法绘制三维曲线、plot_surface()方法绘制三维曲面、scatter()方法绘制三维散点图或bar3d()方法绘制三维柱状图了。
from mpl_toolkits.mplot3d import Axes3D # 创建数据 x = [1, 2, 3, 4, 5]y = [5, 4, 3, 2, 1]z = [1, 2, 3, 4, 5]# 创建图形对象 fig = plt.figure()# 添加一个子图,并指定为3D类型 ax = fig.add_subplot(111, projection='3d')# 绘制散点图 ax.scatter(x, y, z)# ...
通过ax.scatter3D() 函数可以绘制 3D 散点图,示例代码如下: from mpl_toolkits import mplot3d import numpy as np import matplotlib.pyplot as plt fig = plt.figure() #创建绘图区域 ax = plt.axes(projection='3d') #构建xyz z = np.linspace(0,1,100) ...
首先,我们来创建一个最基本的 3D 散点图。这需要使用mpl_toolkits.mplot3d.Axes3D类来创建一个 3D 坐标轴,然后使用scatter方法绘制散点。 importmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dimportnumpyasnp fig=plt.figure()ax=fig.add_subplot(111,projection='3d')x=...
[<mpl_toolkits.mplot3d.art3d.Line3D at 0x1f0ee3b35d0>]4. 三维散点图 fig = plt.figure(figsize=(5, 3))axes = Axes3D(fig, auto_add_to_figure=False)fig.add_axes(axes)# 画散点图x = np.random.rand(50)y = np.random.rand(50)z = np.random.rand(50)axes.scatter(x, y, z, ...
ScatterPlot WireframePlot SurfacePlot ContourPlot FilledContourPlot PolygonPlot BarPlot Text 写在篇后 写在篇前 matplotlib也支持三维作图,但是相对于matlab来讲,感觉功能更弱。当然话说回来,三维作图用的场景相对也更少,所以呢,有一定的知识储备就够了。matplotlib绘制三维图形依赖于mpl_toolkits.mplot3d,用...