如何在 MATLAB 中栅格化曲面图,同时将轴保持为矢量图形?

发布于 2025-01-13 04:38:09 字数 636 浏览 0 评论 0原文

我正在 MATLAB 中制作 3D 曲面图,我想光栅化曲面图(以节省图像大小和加载速度),同时将图形的其余部分(例如,轴、标签、标题等)保留为矢量图形。我该怎么做?现在我有以下内容:

x = linspace(-2, 2, 201);
y = linspace(-2, 2, 201);
[X, Y] = meshgrid(x, y);
Z = sin(sqrt(X.^2 + Y.^2));

fig = figure;

colormap parula
surf(X, Y, Z, 'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceLighting', 'gouraud')
daspect([4 4 1])
axis tight
view(-50, 30)
camlight left

exportgraphics(fig, 'test_matlab_02.pdf', 'ContentType', 'vector')

如果我将 ContentType 设置为 vector,那么整个图形就是矢量图形。如果我将 ContentType 设置为 image,那么整个图形就会被光栅化。如何为图中的其余特征绘制带有矢量图形的栅格化曲面图?

I am making a 3D surface plot in MATLAB, and I want to rasterize the surface plot (to save image size and loading speed) while keeping the rest of the figure (e.g., axes, labels, titles, etc.) as vector graphics. How can I do this? Right now I have the following:

x = linspace(-2, 2, 201);
y = linspace(-2, 2, 201);
[X, Y] = meshgrid(x, y);
Z = sin(sqrt(X.^2 + Y.^2));

fig = figure;

colormap parula
surf(X, Y, Z, 'FaceColor', 'interp', 'EdgeColor', 'none', 'FaceLighting', 'gouraud')
daspect([4 4 1])
axis tight
view(-50, 30)
camlight left

exportgraphics(fig, 'test_matlab_02.pdf', 'ContentType', 'vector')

If I set ContentType to vector, then the whole figure is vector graphics. If I set ContentType to image, then the whole figure becomes rasterized. How can I have a rasterized surface plot with vector graphics for the remaining features in the figure?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

◇流星雨 2025-01-20 04:38:09

File Exchange 提供 vecrast,在这种情况下可能有效。它应该能够结合光栅化和​​矢量格式。

vecrast函数的描述来看:

vecrast 是一个允许自动保存图形的函数
混合矢量和光栅内容。更具体地说,两份副本
创建感兴趣的图形,rasterFigure 和 vectorFigure。补丁,
表面、轮廓、图像和灯光保存在 rasterFigure 中,但是
从矢量图中删除。 rasterFigure 然后保存为临时
具有所需分辨率的 .png 图像。 .png 文件随后是
插入到向量图中,结果保存在一个单独的
矢量文件。

该函数能够处理 2D 和 3D 绘图,如注释中所述:

  • 光栅图形的图形平滑(抗锯齿)功能已关闭。这提高了图像边缘和边缘处的清晰度
    同时大大减小了文件大小。您可以在
    通过设置“GraphicsSmoothing”、“on”(第 97 行)来编写脚本。
  • 建议分辨率不低于 300 dpi。这确保了光栅图像边缘的插值不会导致
    图像在规定轴外出血(用 20dpi 进行测试
    在第一个例子中,你就会明白我的意思)。
  • 引入堆叠选项是为了适应需要图像位于轴后面或前面的 2D 和 3D 绘图,
    分别。这种差异可以从下面的示例中看出。
  • 我强烈建议您查看一下ightPlots 函数,它允许设置精确的图形大小。

File Exchange offers vecrast, which might work in this case. It’s supposed to be able to combine rasterized and vector formats.

From the description of the vecrast function:

vecrast is a function that allows to automatically save a figure with
mixed vector and raster content. More specifically, two copies of the
figure of interest are created, rasterFigure and vectorFigure. Patches,
surfaces, contours, images, and lights are kept in rasterFigure but
removed from vectorFigure. rasterFigure is then saved as a temporary
.png image with the required resolution. The .png file is subsequently
inserted into the vectorFigure, and the result is saved in a single
vector file.

The function is able to handle both 2D and 3D plots, as specified in the notes:

  • The graphics smoothing (anti-aliasing) is turned off for the raster figure. This improves sharpness at the borders of the image and at the
    same time greatly reduces file size. You may change this option in the
    script by setting 'GraphicsSmoothing', 'on' (line 97).
  • A resolution of no less than 300 dpi is advised. This ensures that interpolation at the edges of the raster image does not cause the
    image to bleed outside the prescribed axis (make a test with 20dpi
    on the first example and you will see what I mean).
  • The stacking option has been introduced to accomodate 2D and 3D plots which require the image behind or in front the axis,
    respectively. This difference can be seen in the examples below.
  • I strongly advise to take a look at the tightPlots function that allows setting exact sizes of figures.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文