Export surface plot as a vector

27 Ansichten (letzte 30 Tage)
Marko Duranovic
Marko Duranovic am 15 Jan. 2024
Kommentiert: Hassaan am 16 Jan. 2024
Hi,
I'm trying to export a surface plot as a vector but it isn't rendering it properly.
I tried switching renders between OpenGL and Painters. With OpenGl, it creates an image file which looks okay but I need it in vector format so I switch to Painters and it is saved as a vector but it isn't rendered properly.
Here's the code, the data file is attached.
Below are the the images created using the code (on the left in the image format, on the right as a vector - the one showing issues)
Any help is appreciated
Kind regards,
Marko
clear;close all;clc
% load data.mat
load data.mat
% Figure
figure; hold on;
set(gcf,'Renderer', 'opengl')
% plotting the figure
p_sGREEN = surf(xData_1,yData_1,zData_1,'FaceColor','g');
p_sRED = surf(xData_2,yData_2,zData_2,'FaceColor','r');
p_sBLUE = surf(xData_3,yData_3,zData_3,'FaceColor','b');
% adjusting the styles and axes limits
grid on;box on
zlim([0 10]);
xlim([14 18]);
ylim([4.5 10]);
view(-135,45)
exportgraphics(gcf,'Vector.emf','ContentType','vector','BackgroundColor','none')
exportgraphics(gcf,'Image.emf','ContentType','image','Resolution',300)

Akzeptierte Antwort

Hassaan
Hassaan am 15 Jan. 2024
Bearbeitet: Hassaan am 15 Jan. 2024
The issue you are encountering is a common challenge when exporting 3D surface plots as vector graphics in MATLAB. The Painters renderer, which is typically used for vector graphics, sometimes struggles with complex 3D plots, leading to improper rendering. A few tips and alternative approaches you might consider:
  1. Simplify the Plot: If your surface plot is very dense (has many faces), consider simplifying it. Too many faces can overwhelm the vector renderer. You can do this by reducing the resolution of your data.
  2. Export as PDF or SVG: Sometimes, exporting to formats like PDF or SVG can yield better results than EMF for complex 3D plots.
  3. Use OpenGL for Raster and Convert to Vector: If the OpenGL renderer gives a good raster image, consider using software outside MATLAB to convert the raster image to a vector format. This can sometimes produce better results, though it may not be ideal for highly detailed plots.
  4. Plot Tuning: Adjust the complexity of your plot. Sometimes, removing or simplifying elements like lighting, shadows, or transparency can make the plot more compatible with vector rendering.
  5. Manual Tweaks: After export, you might need to manually tweak the vector file in a vector graphics editor like Adobe Illustrator or Inkscape.
  6. Alternative Plotting Tools: Consider using other MATLAB plotting tools that might render better in vector format, or external tools that specialize in 3D rendering.
  7. Export as Raster at High Resolution: If vector graphics are not absolutely necessary and the primary goal is clarity, exporting your plot as a high-resolution raster image can be a practical solution.
clear; close all; clc
% load data.mat
load data.mat
% Create figure
figure; hold on;
set(gcf, 'Renderer', 'painters') % Using Painters for vector graphics
% Plot the data
p_sGREEN = surf(xData_1, yData_1, zData_1, 'FaceColor', 'g', 'EdgeColor', 'none');
p_sRED = surf(xData_2, yData_2, zData_2, 'FaceColor', 'r', 'EdgeColor', 'none');
p_sBLUE = surf(xData_3, yData_3, zData_3, 'FaceColor', 'b', 'EdgeColor', 'none');
% Adjust styles and axes limits
grid on; box on;
zlim([0 10]);
xlim([14 18]);
ylim([4.5 10]);
view(-135, 45);
% Export as vector graphics
exportgraphics(gcf, 'Vector.pdf', 'ContentType', 'vector', 'BackgroundColor', 'none');
% Export as high-resolution raster image
exportgraphics(gcf, 'Image.png', 'ContentType', 'image', 'Resolution', 300);
In this code, I've set the edge color of the surfaces to 'none' to simplify the plot, which might help with rendering issues. Also, I've changed the export file formats to PDF for vector and PNG for a high-resolution image. You can try different file formats like SVG or EPS for vector output to see if they render better.
If you still encounter issues with the vector output, consider manually editing the vector file in a graphic editor or using a raster-to-vector conversion tool as a last resort. Remember that complex 3D plots can be particularly challenging to render accurately in vector format, so sometimes a compromise between plot complexity and export format is necessary.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
  • Technical Services and Consulting
  • Embedded Systems | Firmware Developement | Simulations
  • Electrical and Electronics Engineering
Feel free to contact me.
  2 Kommentare
Marko Duranovic
Marko Duranovic am 16 Jan. 2024
Hi,
Thanks for your detailed reply. I ended up converting the raster to vector using Inkscape.
Thank you,
Marko
Hassaan
Hassaan am 16 Jan. 2024
@Marko Duranovic You are welcome.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by