另存为jpg后将填充背景移到底部 [英] Moving fill background to the bottom after saving as jpg

查看:63
本文介绍了另存为jpg后将填充背景移到底部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用fill或viscircles函数绘制带有图背景的圆时,如图所示,它按预期显示在图的顶部,但保存为jpg或png后,背景移至图的底部情节,不再可见.

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.

我该如何解决?

注意:不是因为白色是透明色.我尝试了灰色,我尝试了红色,两者的表现都与白色相同.

note: it's not because white is transparent color. I tried gray, I tried red, both are behaving the same as white.

推荐答案

请考虑以下示例(基于MATLAB 2015a):

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'

将输出保存到.jpg时,我得到以下结果(与图中的预览相同):

When saving the output to .jpg I get the following result (which is identical to the preview within the figure):

请注意第二个代码单元中的FaceColor属性,该属性在第一个对象中不存在.问题似乎是您使用的 viscircles 函数是不应该绘制带有背景的形状,而是绘制一条线.我不清楚为什么您会以这种方式(即有背景)查看预览.

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).

旁注:viscircles'DrawBackgroundCircle'选项仅会为轮廓绘制一些白色背景.

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对象.请注意,这些要求您以figure单位(而不是轴'!)提供坐标.
  • 使用填充的多边形:

  • Using 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);

[摘录基于对此提交内容的评论]

用巨型标记绘图:

plot(0.5,0.5,'.r','MarkerSize',70);

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.

这篇关于另存为jpg后将填充背景移到底部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆