Which is the fastest way to plot several 2D contours on one 3D plot?

조회 수: 3 (최근 30일)
Denis Perotto
Denis Perotto 2019년 3월 14일
답변: Avni Agrawal 2024년 9월 5일
I need to plot several 2D rectangle contours on one 3D plot like this:
RESULTS_TEMP.png
To plot these contours I have more than 200000 dots with corresponding X, Y, Z coordinates and vector V with results of my calculations. The color is based on value from V, not on the level of the dot (for this I created a custom non-even colormap). I didn't find a normal way to plot my results, so I did it by cycling fill3() to plot rectangles nearly 50000 times. Even this cost me 70 seconds of plot time, 65GB RAM and wild lags. 20 cores on my workstation didn't help. I succeded in saving the figure, but couldn't rotate or move it.
Can you suggest me another way to solve my problem?

답변 (1개)

Avni Agrawal
Avni Agrawal 2024년 9월 5일
I understand that you are trying to plot a large number of 2D contours in a 3D plot can be computationally intensive, especially when dealing with 200,000 points. Using fill3 repeatedly is not optimal. Instead, consider using patch or surf with vectorized operations to improve performance. Here are some strategies to optimize your plotting:
Strategies for Faster 3D Contour Plotting:
1 Use patch with Vectorization:
% Example data setup
numRects = 50000; % Number of rectangles
X = rand(4, numRects); % X-coordinates
Y = rand(4, numRects); % Y-coordinates
Z = rand(4, numRects); % Z-coordinates
C = rand(1, numRects); % Color data
% Single patch object
figure;
patch('XData', X, 'YData', Y, 'ZData', Z, 'FaceVertexCData', C, ...
'FaceColor', 'flat', 'EdgeColor', 'none');
colormap(yourCustomColormap); % Use your custom colormap
colorbar;
2. Use surf for Grids:
% Grid data example
[X, Y] = meshgrid(linspace(0, 1, 100));
Z = peaks(100); % Example Z data
C = rand(size(Z)); % Color data
% Plot with surf
figure;
surf(X, Y, Z, C, 'EdgeColor', 'none');
colormap(yourCustomColormap);
colorbar;
3. Reduce Data Resolution:
% Downsample data
X = X(:, 1:10:end);
Y = Y(:, 1:10:end);
Z = Z(:, 1:10:end);
C = C(:, 1:10:end);
4.Optimize Rendering:
  • Use OpenGL: set(gcf, 'Renderer', 'OpenGL');
  • Adjust figure properties: set(gca, 'SortMethod', 'childorder');
I hope this helps!

카테고리

Help CenterFile Exchange에서 Contour Plots에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by