Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to get set gca Patch Faces color

169 views
Skip to first unread message

David T

unread,
Feb 22, 2010, 4:31:05 PM2/22/10
to
Hello and thanks for taking the time to read through this. This must be a simple set/get issue but i can't locate the proper property name. I want to set the color of the background of a map. This is refered to as "Patch Face" in figure property editor however i want to be able to set this color with in my initial script.

i've tried: set(gca,'color','r') with no change. I've attempted to assign a handle to the Patch Face however matlab doesn't seem to recognize the property. Any and all help is greatly appreciated.

Some script so it may make more sense of what i'm creating:
m_proj('equidistand cylindrical','long',lonrange,'lat',latrange);
m_pcolor(lon(:,:),lat(:,:),DATA(:,:));
shading flat
set(gca,'visible','off); %tried it on with 'on' with no coloration difference
m_grid('xtick',8,'tickdir...

The map is of the planet and all ocean is listed at 'NaN' so whatever the background color is should show through.

David T

unread,
Feb 22, 2010, 6:11:04 PM2/22/10
to
In my ventures while trying to figure this out i've realized a few things.

whitebg([.402 .6 1]) %does not change gca color only gcf color when using m_map
Y = get(gca,'color') %returns Y = 1 1 1 (which is true, the figure background is white)

set(Y,'color',[.402 .6 1]) %changes the gcf background color to [.402 .6 1] not gca

Y = get(gca,'color') %Still returns Y = 1 1 1;

I then..

T = get(Y,'color');
T=
{0.402,0.6,1}
{0.402,0.6,1}
{0.402,0.6,1}

I'm not sure where to go from here.

Rich Ellis

unread,
Feb 23, 2010, 10:47:27 AM2/23/10
to
The statement

Y = get(gca,'color')

returns an RGB triple (as you point out)

However, Y is not the handle of an axes. However, because Y contains a 1, it
is mistaken for the integer handle of the figure.

The first argument in a call to SET and GET must be the a handle (or an
array of handles). If you want to set the background color of the current
figure, use:

set(gcf,'Color',....)

The statement:

T = get(Y,'color');

returns the color of the figure with integer handle 1 three times.

"David T" <dtra...@gmail.com> wrote in message
news:hlv2u8$5ge$1...@fred.mathworks.com...

David T

unread,
Feb 23, 2010, 1:57:05 PM2/23/10
to
You are absolutely correct and thank you for the response. However, set(gcf,'Color',...); only changes the background outside of the gridded area (for this application). I need to change the background within the gridded area.

I've tried:

set(gcf,'Color',...)
set(gca,'Color',...)
whitebg(gcf,'Color',...);
whitebg(gca,'Color,...);
whitebg(colorspec);

nothing still. . .

The frustrating thing is that i can alter the gridded background color in figure editor to whatever color i want. This means there has to be a handle and a way to do this within a script. I'm beginning to think there is something within the m_mapping package that is stopping me. Would be great to figure this out.

Rich Ellis

unread,
Feb 23, 2010, 6:18:45 PM2/23/10
to
Perhaps the object handle is hidden. Try this:

set(0,'ShowHiddenHandles','on')

and get the handle of the object from the figure or axes Children property.

For example, this statement can show you what object are in the current
axes.

get(get(gca,'Children'),'Type')

Also, see the help for the FINDOBJ function:

doc findobj

"David T" <dtra...@gmail.com> wrote in message

news:hm18e1$pvq$1...@fred.mathworks.com...

David T

unread,
Feb 23, 2010, 6:51:06 PM2/23/10
to
Rich,
Thanks for the help. It literally took me all day, i just figured it out. It is a hidden handle but i was able to get to it a different way:
For some reason i was unable to display the gca handles without having clicked onto the plot. The only way it would work was by..

..and again i wanted this to be fully automated within my script..

T = get(fig,'Children');%third value listed is the gca handle
R = get(T(3,1),'Children');%the 21st value of R is the Patch handle for the background of a plot.
L = R(21,1);
set(L,'FaceColor',[.4 .6 1]);

happy to have that figure out and thanks for the help.


"Rich Ellis" <ri...@mathworks.com> wrote in message <hm1non$p90$1...@fred.mathworks.com>...

leela

unread,
May 27, 2013, 7:04:47 PM5/27/13
to
Thanks, this topic has saved me hours of work!

To make it a little more flexible you can automate the finding of the element of T which relates to the patch handle:

T = get(gca,'Children');
Ttype = get(T,'Type');
set(T(strcmp(Ttype,'patch')),'FaceColor',[0.4 0.6 1]);
0 new messages