When I use fill or viscircles functions to plot circles with background to the plot, in figure it appears on the top of the plot, as it was intended, but after saving as jpg or png, the background moves to the bottom of the plot and is not visible anymore.
How do I fix this?
note: it's not because white is transparent color. I tried gray, I tried red, both are behaving the same as white.
Please consider the following example (made on MATLAB 2015a):
figure(); h=cell(1);
%% viscircles method:
subplot(1,2,1);
plot([0 1],[0,1]); set(gca,'Color',0.8*[1 1 1]); axis square;
h{1} = viscircles([0.5,0.5], 0.1,'EdgeColor','k','DrawBackgroundCircle',false);
get(h{1},'Children')
%// Line with properties:
%//
%// Color: [0 0 0]
%// LineStyle: '-'
%// LineWidth: 2
%// Marker: 'none'
%// MarkerSize: 6
%// MarkerFaceColor: 'none'
%// XData: [1x182 double]
%// YData: [1x182 double]
%// ZData: [1x0 double]
%% Annotation method:
subplot(1,2,2);
plot([0 1],[0,1]); set(gca,'Color',0.8*[1 1 1]); axis square;
pos = get(gca,'position');
h{2} = annotation('ellipse',[pos(1)+pos(3)*0.5 pos(2)+pos(4)*0.5 0.1 0.1],...
'FaceColor','w')
%// Ellipse with properties:
%//
%// Color: [0 0 0]
%// FaceColor: [1 1 1]
%// LineStyle: '-'
%// LineWidth: 0.5000
%// Position: [0.7377 0.5175 0.1000 0.1000]
%// Units: 'normalized'
When saving the output to .jpg
I get the following result (which is identical to the preview within the figure):
Notice the FaceColor
property in the 2nd code cell, which is absent in the 1st object. The problem seems to be that the viscircles
function you used is not supposed to draw a shape with a background, rather, it draws a line. It is unclear to me why you see the preview the way you do (i.e. with a background).
Sidenote: the 'DrawBackgroundCircle'
option for viscircles
merely draws some white background for the outline.
You should try some alternate ways to plot filled circles, such as:
annotation
objects as in my example above. Note that these require you to provide coordinates in figure
units (and not axes'!).Using filled polygons:
N=20; c=[0.5,0.5]; r=0.1; color = [1 1 1];
t = 2*pi/N*(1:N);
hold all; fill(c(1)+r*cos(t), c(2)+r*sin(t), color);
[ snippet is based on a comment of this submission ]
Plotting with giant markers:
plot(0.5,0.5,'.r','MarkerSize',70);
or
scatter(0.5,0.5,70,'r','filled');
[ snippet is based on this answer ]. As mentioned in the link, the downside here is that marker size doesn't change with zoom.
.emf
), edit it (with something like InkScape), bring the background circles to a higher layer and export it.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With