ax = fig.add_subplot(111, projection='3d')# 绘制三维曲面图surf = ax.plot_surface(X, Y, Z, cmap=cm.viridis)# 添加颜色条fig.colorbar(surf, ax=ax, shrink=0.5, aspect=5)# 显示图形plt.show()# 保存图形plt.savefig('3d_surface_plot.png', dpi=300)...
参考: 3D surface (colormap)matplotlib.org/stable/gallery/mplot3d/surface3d.html https://ikuz.eu/machine-learning-and-computer-science/the-concept-of-conjugate-gradient-descent-in-python/ikuz.eu/machine-learning-and-computer-science/the-concept-of-conjugate-gradient-descent-in-python/ 有:...
5,50)y=np.linspace(-5,5,50)X,Y=np.meshgrid(x,y)# 计算Z值Z=np.sin(np.sqrt(X**2+Y**2))# 创建3D图形fig=plt.figure(figsize=(10,8))ax=fig.add_subplot(111,projection='3d')# 绘制表面surf=ax.plot_surface(X,Y,Z,cmap='coolwarm')# 添加颜色条fig.colorbar...
5,100)y=np.linspace(-5,5,100)X,Y=np.meshgrid(x,y)Z=np.sin(np.sqrt(X**2+Y**2))# 创建 3D 表面图fig=plt.figure(figsize=(12,8))ax=fig.add_subplot(111,projection='3d')surf=ax.plot_surface(X,Y,Z,cmap='viridis')fig.colorbar(surf,label='Z Value')ax.set...
SurfacePlot ContourPlot FilledContourPlot PolygonPlot BarPlot Text 写在篇后 写在篇前 matplotlib也支持三维作图,但是相对于matlab来讲,感觉功能更弱。当然话说回来,三维作图用的场景相对也更少,所以呢,有一定的知识储备就够了。matplotlib绘制三维图形依赖于mpl_toolkits.mplot3d,用法也比较简单,只需要一个...
本文将介绍如何使用Python中的Matplotlib和mpl_toolkits.mplot3d库绘制令人印象深刻的3D曲面图。准备工作首先,确保你的Python环境中安装了Matplotlib库。...如果还没有安装,可以使用pip进行安装:pip install matplotlib导入必要的库在开始之前,让我们先...
使用相应的 3D 绘图函数来绘制数据,例如: 散点图:ax.scatter(x, y, z, c='color', marker='marker_style', label='label') 曲面图:ax.plot_surface(X, Y, Z, cmap='colormap') 线图:ax.plot(x, y, z, label='label') 柱状图:ax.bar3d(x, y, z, dx, dy, dz, shade=True) ...
plt.plot(x, np.sin(x -4), color=(1.0,0.2,0.3))# RGB元组的颜色值,每个值介于0-1 plt.plot(x, np.sin(x -5), color='chartreuse');# 能支持所有HTML颜色名称值 如果没有指定颜色,Matplotlib 会在一组默认颜色值中循环使用来绘制每一条线条。
plt.colorbar.colorbar() cmap展示 范围较大的处理 离散色标 坐标轴设置 大小刻度线 影藏刻度或标签 多子图坐标标签拥挤问题 自定义坐标轴 直方图、边际图和密度图 plt.hist() scipy.stats.gaussian_kde核密度估计 一维KDE 二维KDE 将多组直方图放到一起 二维直方图 mplot3D绘制三维图 contour3D三维等高线图 view...
importmatplotlib.pyplot as pltfrommpl_toolkits.mplot3dimportAxes3Dimportnumpy as np 点击下方链接可前往各小节 使用指南1 - 绘图结构 (图像,坐标轴/子图,显示,保存) 使用指南2 - 绘图设置 (投影类型,字体,颜色,标题,坐标轴,图例,标记样式,线条样式,透明度,旋转,子图布局) ...