我想知道如何繪製多個,2D等高線圖中的z軸間隔開,在3D圖像這樣:情節多個2D等高線圖
回答
注意:這個答案的第一部分是爲HG1圖形。如果您使用MATLAB R2014b或更高版本(HG2),請參閱第二部分。
HG1:
的contour
函數在內部創建許多patch
對象,並且返回它們作爲組合hggroup object。因此,我們可以通過將Z尺寸移動到所需的水平(默認輪廓在z = 0處顯示)來設置所有貼片的ZData
。
下面是一個例子:
[X,Y,Z] = peaks;
surf(X, Y, Z), hold on % plot surface
[~,h] = contour(X,Y,Z,20); % plot contour at the bottom
set_contour_z_level(h, -9)
[~,h] = contour(X,Y,Z,20); % plot contour at the top
set_contour_z_level(h, +9)
hold off
view(3); axis vis3d; grid on
下面是上述用於set_contour_z_level
功能的代碼:
function set_contour_z_level(h, zlevel)
% check that we got the correct kind of graphics handle
assert(isa(handle(h), 'specgraph.contourgroup'), ...
'Expecting a handle returned by contour/contour3');
assert(isscalar(zlevel));
% handle encapsulates a bunch of child patch objects
% with ZData set to empty matrix
hh = get(h, 'Children');
for i=1:numel(hh)
ZData = get(hh(i), 'XData'); % get matrix shape
ZData(:) = zlevel; % fill it with constant Z value
set(hh(i), 'ZData',ZData); % update patch
end
end
HG2:
上述解決方案不再以R2014b開始。在HG2中,contour objects不再具有任何圖形對象作爲子項(Why Is the Children Property Empty for Some Objects?)。
幸運的是,有一個簡單的修復,隱藏輪廓屬性稱爲ContourZLevel
。 您可以瞭解更多無證等高線圖的定製here和here。
所以在前面的例子簡直變成:
[X,Y,Z] = peaks;
surf(X, Y, Z), hold on % plot surface
[~,h] = contour(X,Y,Z,20); % plot contour at the bottom
h.ContourZLevel = -9;
[~,h] = contour(X,Y,Z,20); % plot contour at the top
h.ContourZLevel = +9;
hold off
view(3); axis vis3d; grid on
,在適用於所有版本的另一種解決方案是「父」的曲線到hgtransform
對象,變換使用一個簡單的z-translation。像這樣:
t = hgtransform('Parent',gca);
[~,h] = contour(X,Y,Z,20, 'Parent',t);
set(t, 'Matrix',makehgtform('translate',[0 0 9]));
謝謝!這正是我想要繪製的那種形象。 有沒有辦法調整間距/視角,使輪廓不重疊?(我正在繪製輪廓的三個級別,如圖,但是每個輪廓與當前透視圖重疊) – Krish
您可以[交互式旋轉](http://www.mathworks.com/help/matlab/creating_plots /rotate-3d-interactive-rotation-of-3-d-views.html)3D視圖,或以['view(az,el)'](http://www.mathworks.com/ help/matlab/ref/view.html):http://www.mathworks.com/help/matlab/visualize/setting-the-viewpoint-with-azimuth-and-elevation.html。您也可以[控制相機](http://www.mathworks.com/help/matlab/visualize/view-control-with-the-camera-toolbar.html)以獲得更大的靈活性 – Amro
我已經更新了答案展示HG1和HG2的解決方案 – Amro
- 1. GNU情節2D曲線
- 2. 情節2D線由線等式中使用Python Matplotlib
- 3. R - 等高線圖
- 4. Matlab等高線圖
- 5. R - 等高線圖
- 6. 情節2D矩陣
- 7. gnuplot的2D情節3D圍欄情節
- 8. 造型背景圖像的情節線在高位圖
- 9. 創建等高線圖
- 10. 蟒蛇等高線圖
- 11. 的JFreeChart線圖情節OHLCDataItem
- 12. 平滑2D情節MATLAB
- 13. 顏色循環用於多個matplotlib pyplot等高線圖
- 14. 多個ggplot2情節與情節
- 15. 用隱藏軸顯示高位地圖的情節線?
- 16. 視覺藝術品繪製2D功能等高線圖(使用FPlot)時
- 17. Matplotlib:在單個情節繪製multple線圖(離散曲線)
- 18. FusionCharts的XT - 多系列線圖2D
- 19. Mathematica中2D圖上的多個線段的圖形
- 20. 等高線算法
- 21. 在同一個情節繪製多個函數曲線
- 22. JS或PHP中的等高線圖?
- 23. 錯誤與等高線圖GGPLOT2
- 24. matlab等高線圖特定值
- 25. 蟒蛇matplotlib:在等高線圖
- 26. 等高線圖python中的長誤差
- 27. 在等高線圖上繪製點
- 28. 等高線圖與附標量
- 29. Matlab等高線圖平滑的顏色
- 30. 等高線圖的三維矢量
您可能要查找的命令是[contourslice](http://www.mathworks.com/help/matlab/ref/contourslice.html)。請參閱文檔以作進一步參考 – CitizenInsane
@CitizenInsane:該功能旨在可視化體數據,我不認爲OP意味着在這裏做到這一點。 – Amro
@Amro Humm可能很容易將數據視爲體積數據。你的解決方案很好。 – CitizenInsane