首页 文章

在matplotlib图表一个色的立方体

提问于
浏览
8

我研究一种统计代码,用Matlab生成各种图形 . 图表类型的范围从简单的饼图和条形图到3D直方图格子 .

现在我们想要一个很好的GUI来使用该软件 . 我们有一个原型Matlab GUI,但Matlab的GUI有很多问题,所以我们想转向更强大的GUI . 我最好的选择似乎是PySide matplotlib,但到目前为止我还没有找到一种绘制3D点阵的方法 . matlab代码使用contourslice . 在matplotlib中似乎没有类似的调用 . 所以,任何人都可以帮我弄清楚如何使用matplotlib获得这样的图形吗?到目前为止,我唯一的想法是将6个曲面图形化为立方体 .

实际上,也欢迎其他GUI / Graph库组合的建议 . 基本统计代码是C,因此Python只是众多选项中的一种 . 从我在StackOverflow上看到的一些答案来看,matplotlib在3D中可能会慢得令人无法接受 . 也许R会更好?

A colored 3D cube made with contourslice

这是matlab代码:

clf
xlo = -1.800000e+01; 
xhi = 1.000000e+01; 
ylo = 1.000000e+01; 
yhi = 3.000000e+01; 
zlo = -1.000000e+03; 
zhi = 1.000000e+03; 
X=zeros(16,16,16);
Y=zeros(16,16,16);
Z=zeros(16,16,16);
V=zeros(16,16,16);
% fill in X, Y, Z, and V  huge amount of text
xt = [-1.800000e+01:2.800000e-01:1.000000e+01];
yt = [1.000000e+01:2.000000e-01:3.000000e+01];
zt = [-1.000000e+03:2.000000e+01:1.000000e+03];
isoval = -1.428280e+01;
h = patch(isosurface(X,Y,Z,V,isoval),... 
'FaceColor', 'blue', ... 
'EdgeColor', 'none', ... 
'AmbientStrength', 0.2, ... 
'SpecularStrength', 0.7, ... 
'DiffuseStrength', 0.4);
isonormals(X,Y,Z,V,h);
patch(isocaps(X,Y,Z,V,isoval), ...
'FaceColor', 'interp', ... 
'EdgeColor', 'none'); 
axis([xlo xhi ylo yhi zlo zhi])
daspect([2.800000e+01,2.000000e+01,2.000000e+03])
set(gca,'linewidth',2)
set(gca,'fontweight','bold')
set(gca,'fontsize',12)
grid on
box on
colormap('default'); colorbar

view(3) 
set(gcf,'Renderer','zbuffer')
lighting phong
cin = 'n';
if (cin == 'y')
xin = questdlg('Axis to slide through ?', 'Axis', 'X', 'Y', 'Z', 'X');
xin = lower(xin);
for i = 1 : 101
if gcf ~= plotFigure
return
end
if (xin == 'y')
h = contourslice(X,Y,Z,V,xt(i),[],[],101);
elseif (xin == 'x')
h = contourslice(X,Y,Z,V,[],yt(i),[],101);
elseif (xin == 'z')
h = contourslice(X,Y,Z,V,[],[],zt(i),101);
end
axis([-1.8000e+01  1.0000e+01  1.0000e+01  3.0000e+01 -1.0000e+03  1.0000e+03 -8.6774e+01  4.2066e+02])
set(gca,'linewidth',2)
set(gca,'fontweight','bold')
set(gca,'fontsize',12)
grid on
box on
view(3)
set(h, 'Linewidth', 10)
colorbar
pause(0.3)
if (i < 101)
clf
end
end
end

1 回答

  • 2

    您可能需要查看mayavi如果您使用的是Windows,则默认使用Python(x,y) .

相关问题