files, tool windows, actions, and settings.importmatplotlib.pyplotaspltimportnumpyasnpfrommpl_toolkits.mplot3dimportAxes3Ddefscatter():# 数据大小n=1024# 生成 n 个X值,符合标准正态分布X=np.random.normal(0,1,n)# 生成
from mpl_toolkits.mplot3d import Axes3D 然后使用下面的两种方式之一声明要创建三维子图: ax = fig.gca(projection='3d') ax = plt.subplot(111, projection='3d') 接下来就可以使用ax的plot()方法绘制三维曲线、plot_surface()方法绘制三维曲面、scatter()方法绘制三维散点图或bar3d()方法绘制三维柱状图了。
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轴数...
绘制散点图使用scatter()方法,将散点颜色设置为绿色,红色边沿。 代码示例如下: importmatplotlib.pyplotaspltimportnumpyasnpfrommpl_toolkits.mplot3dimportAxes3D plt.rcParams['font.sans-serif'] = ['STKAITI']plt.rcParams['axes.unicode_minus'] = Falseplt.rcParams['axes.facecolor'] = '#cc00ff'fig=pl...
之前,我们已经尝试了用Python + matplotlib来绘制二维贝塞尔曲线。今天,我们看看如何用Python + matplotlib来绘制三维贝塞尔曲面。 备注:请参考《Python快速安装实践 – 2024甲辰龙年版》安装Pipenv,然后创建一个matplotlib虚拟环境,并安装matplotlib 再用你熟悉的编辑器输入以下代码,保存为bezier_surface.py: ...
ScatterPlot WireframePlot SurfacePlot ContourPlot FilledContourPlot PolygonPlot BarPlot Text 写在篇后 写在篇前 matplotlib也支持三维作图,但是相对于matlab来讲,感觉功能更弱。当然话说回来,三维作图用的场景相对也更少,所以呢,有一定的知识储备就够了。matplotlib绘制三维图形依赖于mpl_toolkits.mplot3d,用...
import matplotlib.pyplot as plt import numpy as np plt.figure(figsize=(8,8),dpi=90) x=np.random.rand(60)*2 y=np.random.rand(60)*2 colors=np.random.rand(60) area=np.pi*(15*np.random.rand(50))**2 plt.scatter(x,y,s=area,c=colors,alpha=0.7,marker=r"$\clubsuit$") ...
8))ax=fig.add_subplot(111,projection='3d')# 绘制散点图scatter=ax.scatter(x,y,z)# 设置轴标签ax.set_xlabel('X轴 - how2matplotlib.com')ax.set_ylabel('Y轴 - how2matplotlib.com')ax.set_zlabel('Z轴 - how2matplotlib.com')# 设置标题ax.set_title('基础3D散点图 - how2matplotlib.com...
fig.update_layout(title='3D Scatter Plot of Iris Dataset')# 显示图形fig.show()```3. SeabornSeaborn是一个基于matplotlib的数据可视化库,提供了更高级别的界面和多种美观的图形类型。使用Seaborn进行三维可视化可以使用其3D绘图功能,即seaborn的tsplot和其他3D图形。下面是一个简单的例子,展示如何使用Seaborn进行...
importnumpyasnpimportmatplotlib.pyplotaspltfrommpl_toolkits.mplot3dimportAxes3Dfig=plt.figure(figsize=(8,6))ax=fig.add_subplot(111,projection='3d')# 生成随机数据n=100x=np.random.rand(n)y=np.random.rand(n)z=np.random.rand(n)colors=np.random.rand(n)sizes=1000*np.random.rand(n)scatter=...