I'm trying to save matlab figure files where I've set the transparency of the plot lines using the fourth element in the color vector.
p1 = line(x,y,'Color',[0 0 0 .1],'LineStyle','-','Marker','.');saveas(curr_fig1,'myfig1.fig');
However, when I open the figure (either by double clicking it in file explorer, or by using the open or openfig commands) the plots no longer have any transparency. Does anyone know a way around this? Here is a full snippet of code that can be run independently to highlight the problem.
clear; close all;curr_fig1 = figure();x = 0:.1:2;y = sin(x);figure(1);p1 = line(x,y,'Color',[0 0 0 .1],'LineStyle','-','Marker','.');saveas(curr_fig1,'myfig1.fig');openfig('myfig1.fig');savefig(curr_fig1,'myfig2.fig');openfig('myfig2.fig');
UPDATE:
It seems that the specific issue is that the Line.Edge.ColorData is not preserved during the saving process.
To highlight what I mean by this, try running the code below.
clear; close all;curr_fig1 = figure();x = 0:.1:2;y = sin(x);f1 = figure(1); % figure f1
p1 = line(x,y,'Color',[0 0 0 .1],'LineStyle','-','Marker','.'); % line p1 is a child of axes a1, which is a child of f1
a1 = f1.Children(1); % axes a1 are child of figure f1 (this variable is not used, but can be examined)
saveas(curr_fig1,'myfig1.fig','m');f2 = openfig('myfig1.fig'); % figure f2
a2 = f2.Children(1); % axes a2 are the axes of figure f2
p2 = a2.Children(1); % Line p2 is a child of axes a2
% Nominally, we would want the Edge.ColorData to be the same for the object that
% I saved and the object that I opened. However, this is not the case.
disp('The Edge.ColorData for the original line p1 is:')display(p1.Edge.ColorData)disp('')disp('The Edge.ColorData for the saved/opened line p2 is:')display(p2.Edge.ColorData)% We can further notice that when I save and reopen, the Edge.ColorType changes
% from 'truecoloralpha' to 'truecolor', which may be part of the problem
disp('The Edge.ColorData for the original line p1 is:')display(p1.Edge.ColorType)disp('')disp('The Edge.ColorData for the saved/opened line p2 is:')display(p2.Edge.ColorType)
I'm trying to find a way to force MATLAB to recognize the fact that I've changed these properties, and save the values that I've assigned to them.
CONTEXT:
The reason that I'm using transparency is to see when there is a high density of data in certain regions, so the interaction of transparency between different lines is important. Here's an example of a plot that I create. It is a plot that contains about 2000 curves in a confined space. Before saving, the transparency works and I am able to see where the curves are dense. After saving and reopening, the figure is just a mess of fully opaque pixels.
To create the following image, I save as pdf:
To create the following image, I save as fig, reopen as fig, and save as pdf:
Best Answer