Python能否实现媲美Matlab的3D曲面图效果及代码转换
注意: 这不是一个单纯的代码转换问题,核心是验证Python是否具备产出与Matlab同等质量的3D绘图的能力。
我已使用Matlab绘制出如下效果图:
我尝试使用Python复现该图,但最终效果达不到Matlab原图的质量。请问是否有Python工具包可以实现与上述Matlab原图一致的绘图效果?如果存在,请将我提供的Matlab代码转换为Python版本。以下是我编写的Matlab代码:
set(groot,'defaultAxesTickLabelInterpreter','latex'); set(groot,'defaulttextinterpreter','latex'); set(groot,'defaultLegendInterpreter','latex'); x0=0; y0=0; width=3000; height=2000; set(gcf,'position',[x0,y0,width,height]) [X,Y] = meshgrid(-1:.01:1); a = 3; b = 2; Z = a*X.^2 + b*Y.^2; subplot(1,3,1) s = surf(X,Y,Z,'FaceColor','r', 'FaceAlpha',0.5, 'EdgeColor','none'); s.EdgeColor = 'none'; xlabel('$x_1$','Interpreter','latex','FontSize', 15) ylabel('$x_2$','Interpreter','latex','FontSize', 15) zlabel('$f(\mathbf{x};\mathbf{\theta})$','Interpreter','latex','FontSize', 15) legend({'$f([x_1, x_2]^\top; [\theta_1=3,\theta_2=2]^\top)=3x_1^2+2x_2^2$'},'interpreter','latex','FontSize', 10) subplot(1,3,2) Z2 = a*X.^2 ; s2 = surf(X,Y,Z2,'FaceColor','b', 'FaceAlpha',0.5, 'EdgeColor','none'); s2.EdgeColor = 'none'; xlabel('$x_1$','Interpreter','latex','FontSize', 15) ylabel('$x_2$','Interpreter','latex','FontSize', 15) zlabel('$f(\mathbf{x};\mathbf{\theta})$','Interpreter','latex','FontSize', 15) legend({'$f([x_1, x_2]^\top; [\theta_1=3,\theta_2=0]^\top)=3x_1^2$'},'interpreter','latex','FontSize', 10) subplot(1,3,3) s3 = surf(X,Y,Z,'FaceColor','r', 'FaceAlpha',0.5, 'EdgeColor','none'); s3.EdgeColor = 'none'; hold s4 = surf(X,Y,Z2,'FaceColor','b', 'FaceAlpha',0.5, 'EdgeColor','none'); s4.EdgeColor = 'none'; xlabel('$x_1$','Interpreter','latex','FontSize', 15) ylabel('$x_2$','Interpreter','latex','FontSize', 15) zlabel('$f(\mathbf{x};\mathbf{\theta})$','Interpreter','latex','FontSize', 15) legend({'$f(\mathbf{x};\mathbf{\theta})=3x_1^2+2x_2^2$', '$f(\mathbf{x};\mathbf{\theta})=3x_1^2$'},'interpreter','latex','FontSize', 10)
内容的提问来源于Stack Exchange,提问作者Saeed
相关产品推荐
相关产品推荐

