Thread Subject: inconsistency btwn hist and bar ??

Subject: inconsistency btwn hist and bar ??

From: Juliette Salexa

Date: 9 Aug, 2009 02:22:01

Message: 1 of 6

For histograms, the following code WORKS (makes 2 histograms, the 2nd transparent):

x=randn(1,100);y=randn(1,100);
hist(x);hold on
hist(y)
histo = get(gca,'chi');
set(histo(1),'facea',0.5,'edgea',0.5)
hold off
-----------------------------------------
For bargraphs, the following code does NOT WORK:

x=rand(5,1);y=rand(5,1);
bar(x);hold on
bar(y)
baro = get(gca,'chi');
set(baro(1),'facea',0.5,'edgea',0.5)
hold off
-----------------------------------------
??? Error using ==> set
There is no 'facea' property in the 'barseries' class.
-----------------------------------------

It appears that 'FaceAlpha' and 'faceAlpha' don't work for the barseries class either.
Is there any analog of 'facea' for bar graphs ??

If not, I guess I'll have to modify bar.m to incorporate this feature.
I looked through hist.m and searched for both "facea" and "alpha" and found nothing in either case. Does anyone know where the 'facea' feature is incorporated into the hist funciton ?? That way maybe I can incorporate it into the bar funciton ??

Thanks in advance.

Subject: inconsistency btwn hist and bar ??

From: Gustavo Morales

Date: 9 Aug, 2009 02:51:01

Message: 2 of 6

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h5lbs9$fgt$1@fred.mathworks.com>...
> For histograms, the following code WORKS (makes 2 histograms, the 2nd transparent):
>
> x=randn(1,100);y=randn(1,100);
> hist(x);hold on
> hist(y)
> histo = get(gca,'chi');
> set(histo(1),'facea',0.5,'edgea',0.5)
> hold off
> -----------------------------------------
> For bargraphs, the following code does NOT WORK:
>
> x=rand(5,1);y=rand(5,1);
> bar(x);hold on
> bar(y)
> baro = get(gca,'chi');
> set(baro(1),'facea',0.5,'edgea',0.5)
> hold off
> -----------------------------------------
> ??? Error using ==> set
> There is no 'facea' property in the 'barseries' class.
> -----------------------------------------
>
> It appears that 'FaceAlpha' and 'faceAlpha' don't work for the barseries class either.
> Is there any analog of 'facea' for bar graphs ??
>
> If not, I guess I'll have to modify bar.m to incorporate this feature.
> I looked through hist.m and searched for both "facea" and "alpha" and found nothing in either case. Does anyone know where the 'facea' feature is incorporated into the hist funciton ?? That way maybe I can incorporate it into the bar funciton ??
>
> Thanks in advance.

Hi Juliet:

The current axes childrens result to be "patch" objects when you make plots with "hist". By another hand, the childrens are "hggroup" objects when you make plots with "bar". They belongs to different classes, so they have different attributes.

Definitely, -FaceAlpha- does not an attribute for "hggroup" objects.....
Maybe if you can make a class which inherit that property..... I'll try to look into it

Subject: inconsistency btwn hist and bar ??

From: Gustavo Morales

Date: 9 Aug, 2009 03:00:18

Message: 3 of 6

the commands to see the types of objects are:

>> get(histo,'type') % if you current axes has graphics created with "hist"

>> get(baro,'type') % if you current axes has graphics created with "bar"

Subject: inconsistency btwn hist and bar ??

From: matt dash

Date: 9 Aug, 2009 04:28:01

Message: 4 of 6

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h5lbs9$fgt$1@fred.mathworks.com>...
> For histograms, the following code WORKS (makes 2 histograms, the 2nd transparent):
>
> x=randn(1,100);y=randn(1,100);
> hist(x);hold on
> hist(y)
> histo = get(gca,'chi');
> set(histo(1),'facea',0.5,'edgea',0.5)
> hold off
> -----------------------------------------
> For bargraphs, the following code does NOT WORK:
>
> x=rand(5,1);y=rand(5,1);
> bar(x);hold on
> bar(y)
> baro = get(gca,'chi');
> set(baro(1),'facea',0.5,'edgea',0.5)
> hold off
> -----------------------------------------
> ??? Error using ==> set
> There is no 'facea' property in the 'barseries' class.
> -----------------------------------------
>
> It appears that 'FaceAlpha' and 'faceAlpha' don't work for the barseries class either.
> Is there any analog of 'facea' for bar graphs ??
>
> If not, I guess I'll have to modify bar.m to incorporate this feature.
> I looked through hist.m and searched for both "facea" and "alpha" and found nothing in either case. Does anyone know where the 'facea' feature is incorporated into the hist funciton ?? That way maybe I can incorporate it into the bar funciton ??
>
> Thanks in advance.


The patches created by hist are children of the barseries created by bar.
get(baro,'children') and then set facealpha on that.

Subject: inconsistency btwn hist and bar ??

From: Juliette Salexa

Date: 10 Aug, 2009 00:35:19

Message: 5 of 6

Thanks to both of you.
Specifically, thank you Matt for the command get(baro,'children').

It seems this still doesn't work the way I expect though.
Maybe it's just a problem with my verion (R2007b), but I want to confirm whether this is really a bug or if it's just a problem with my code.

Can someone check if the same thing happens on their version ??
-----------------------------------------------------
Appears to make bars transparent at RANDOM:
-----------------------------------------------------
figure(1)
for i=1:9
subplot(3,3,i)
x=rand(5,1);y=rand(5,1);bar(x);
hold on
bar(y)
baro = get(gca,'chi');baro1=get(baro,'children');baro2=cell2mat(baro1);set(baro2(1),'facea',0.5,'edgea',0.5)
hold off
end
-----------------------------------------------------
Even if I make a set of COMPLETELY transparent bars, THEN add new bars, the new ones are opaque RANDOMLY:
-----------------------------------------------------
figure(2)
for i=1:9
subplot(3,3,i)
x=rand(5,1);y=rand(5,1);bar(x);
baro = get(gca,'chi');baro1=get(baro,'children');
set(baro1,'facea',0.5,'edgea',0.5)
hold on
bar(y)
hold off
end
-----------------------------------------------------
I'm not sure if this is a bug or just a problem with my code so if someone can check if the same output occurs on their version I'd be very thankful.

Thanks in advance.

Subject: inconsistency btwn hist and bar ??

From: Juliette Salexa

Date: 20 Aug, 2009 18:38:19

Message: 6 of 6

Okay, so is there a way to get all of the bars of x opaque and all of y transparent in the above example ?? Instead of x completely opaque and unpredictably random bars of y transparent ??

I've been trying for awhile, but it seems I can only do this with hist, but not with bar.

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

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.

Tag Activity for This Thread
Tag Applied By Date/Time
gca Sprinceana 22 Aug, 2009 05:27:40
randn Sprinceana 22 Aug, 2009 05:27:36
bar Sprinceana 22 Aug, 2009 05:27:32
hist Sprinceana 22 Aug, 2009 05:27:32
rssFeed for this Thread

Contact us at files@mathworks.com