python - 在 matplotlib 中绘制彩色立方体

标签 python matlab graph 3d matplotlib

我致力于使用 Matlab 生成各种图表的统计代码。图形类型范围从简单的饼图和条形图到 3D 直方图格。

现在我们想要一个漂亮的 GUI 来配合软件。我们有一个原型(prototype) 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

最佳答案

您可能想看看 mayavi 如果您使用的是 Windows,它默认带有 Python(x,y)。 .

关于python - 在 matplotlib 中绘制彩色立方体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13631236/

相关文章:

matlab - 如何在 MATLAB 中绘制矢量(物理 2D/3D 矢量)?

arrays - 将范围分成间隔并将其输出到数组中

r - 在 y 轴上方添加空间而不用 expand()

r - 在 R 中如何从 igraph 中删除小社区

matlab - 在 MATLAB 中为依赖属性动态分配 getter

graph - D3 在超过 1 个 svg 元素上过渡

Python 和 MySQLdb

python - 如何创建矩阵模板来检查句子相似度?

python - 从配置文件 Python 中读取值

python - OpenCV Python围绕特定点将图像旋转X度