- Use OpenGL: set(gcf, 'Renderer', 'OpenGL');
- Adjust figure properties: set(gca, 'SortMethod', 'childorder');
Which is the fastest way to plot several 2D contours on one 3D plot?
3 views (last 30 days)
Show older comments
I need to plot several 2D rectangle contours on one 3D plot like this:
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?
0 Comments
Answers (1)
Avni Agrawal
on 5 Sep 2024
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:
I hope this helps!
0 Comments
See Also
Categories
Find more on Contour Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!