Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
fill function changes font and adds frame

Subject: fill function changes font and adds frame

From: leo nidas

Date: 24 Aug, 2010 17:19:08

Message: 1 of 4



Hi there,

The following code produces two figures. The first contains the word 'Exponential' and the second a shaded region plus the word "Exponential". The shaded region is created using the fill function.

I watch the two graphs (the only difference should be the shaded region) and I observe a little difference in the font of the word "Exponential" and an extra frame around the white area of the figure.

Why is that? How can I fill areas in a graph that contains text without these changes to take place?

Thanx in advance for any answers!

(I use 2007b, if another version deals with it please let me know!)


close all
clear all
clc

axis([0 6 -2.3 4.3])
hold on

fonts=15.5;

text('Interpreter','latex',...
'String','($Exponential$)',...
'Position',[1.3 1.5],...
'FontSize',fonts)

figure

 t = (1/16:1/8:1)'*2*pi;
 x = sin(t);
 y = cos(t);
 fill(x,y,'k','FaceAlpha',0.2)


axis([0 6 -2.3 4.3])
hold on


fonts=13;

text('Interpreter','latex',...
'String','($Exponential$)',...
'Position',[1.3 1.5],...
'FontSize',fonts)

Subject: fill function changes font and adds frame

From: Alan B

Date: 24 Aug, 2010 17:41:20

Message: 2 of 4

"leo nidas" <bleonidas25@yahoo.gr> wrote in message <i50uuc$5pf$1@fred.mathworks.com>...
>
>
> Hi there,
>
> The following code produces two figures. The first contains the word 'Exponential' and the second a shaded region plus the word "Exponential". The shaded region is created using the fill function.
>
> I watch the two graphs (the only difference should be the shaded region) and I observe a little difference in the font of the word "Exponential" and an extra frame around the white area of the figure.
>
> Why is that? How can I fill areas in a graph that contains text without these changes to take place?
>
> Thanx in advance for any answers!
>
> (I use 2007b, if another version deals with it please let me know!)
>
>
> close all
> clear all
> clc
>
> axis([0 6 -2.3 4.3])
> hold on
>
> fonts=15.5;
>
> text('Interpreter','latex',...
> 'String','($Exponential$)',...
> 'Position',[1.3 1.5],...
> 'FontSize',fonts)
>
> figure
>
> t = (1/16:1/8:1)'*2*pi;
> x = sin(t);
> y = cos(t);
> fill(x,y,'k','FaceAlpha',0.2)
>
>
> axis([0 6 -2.3 4.3])
> hold on
>
>
> fonts=13;
>
> text('Interpreter','latex',...
> 'String','($Exponential$)',...
> 'Position',[1.3 1.5],...
> 'FontSize',fonts)

I'm guessing here, but I think when you change the FaceAlpha value, you force the second figure to use a different renderer ('OpenGL' instead of 'painters' for me). Apparently OpenGL can't handle font-smoothing. I'm not sure why the axis itself looks different.

Subject: fill function changes font and adds frame

From: leo nidas

Date: 24 Aug, 2010 18:02:20

Message: 3 of 4

Thanx Alan for your comment,

Well, is there any way to do this manually then? I mean to manually fill a specific area with transparency from the properties of the figure or something?

(Without changing the font or adding this extra frame?)

Subject: fill function changes font and adds frame

From: Alan B

Date: 24 Aug, 2010 18:35:24

Message: 4 of 4

"leo nidas" <bleonidas25@yahoo.gr> wrote in message <i511fc$lfm$1@fred.mathworks.com>...
> Thanx Alan for your comment,
>
> Well, is there any way to do this manually then? I mean to manually fill a specific area with transparency from the properties of the figure or something?
>
> (Without changing the font or adding this extra frame?)

http://www.mathworks.com/access/helpdesk_r13/help/techdoc/ref/figure_props.html#opengl_autoselection
According to this page, OpenGL is the only renderer that supports transparency. It looks like you have to convince OpenGL to smooth the fonts - I have no idea how or if that is possible. Or, use some annoying workaround like saving a figure as an image, then loading it and drawing text on I that.

I don't really see an extra "frame". I see a change in the grid linestyle, slight changes in the tick/ticklabel locations, and one extra grid line drawn near the upper y limit. Is that what you're referring to? I guess the OpenGL axis draws that extra gridline, even though it does not correspond to a value in the axis' ytick property - I don't know why it does that. You could get that to go away by turning off the grid and manually drawing your own grid lines. Another annoying workaround, that's the best suggestion I have.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us