Thread Subject: two problems with bar graphs

Subject: two problems with bar graphs

From: Juliette Salexa

Date: 7 Jul, 2009 22:08:01

Message: 1 of 8

Please consider the following code:
.........
fullscreen=get(0,'ScreenSize');
figure('Position',[0,-50 fullscreen(3),fullscreen(4)])
for i=1:25
    subplot(5,5,i)
    differences=rand(1,6) ;labels={'CG','AT','GA','GT','CA','CT'};
    bar(differences);set(gca,'XTickLabel',labels);
end
.......

first: in order to have the figure come out in full screen, I need that second line ... but now I can't do "figure(1)" anymore .. so everytime I run my code a new figure is made (unlike if i had the command figure(1), which would cause the new figure 1 to replace the old figure 1 everytime the code is rerun). Does anyone know a way around this ??

second, I don't know if the same is happening to you but my bars are not spread out accorss the entire abscissa ... they're all squished into the left side. Changing the width by the command bar(differences,width) does not help either.. it just changes the widths of the bars, but doesn't spread them out. How can i FORCE matlab to spread them (although it should not need forcing in the first place) ???

thanks
xoxo

Subject: two problems with bar graphs

From: Bruno Luong

Date: 7 Jul, 2009 22:15:20

Message: 2 of 8

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h30h01$nbv$1@fred.mathworks.com>...
> Please consider the following code:
> .........
> fullscreen=get(0,'ScreenSize');
> figure('Position',[0,-50 fullscreen(3),fullscreen(4)])

figure(1);
set(1,'Position',[0,-50 fullscreen(3),fullscreen(4)]);
...

Bruno

Subject: two problems with bar graphs

From: Nathan

Date: 7 Jul, 2009 22:28:19

Message: 3 of 8

On Jul 7, 3:08 pm, "Juliette Salexa" <juliette.physic...@gmail.com>
wrote:
> Please consider the following code:
> .........
> fullscreen=get(0,'ScreenSize');
> figure('Position',[0,-50 fullscreen(3),fullscreen(4)])
> for i=1:25
>     subplot(5,5,i)
>     differences=rand(1,6) ;labels={'CG','AT','GA','GT','CA','CT'};
>     bar(differences);set(gca,'XTickLabel',labels);
> end
> .......
>
> first: in order to have the figure come out in full screen, I need that second line ... but now I can't do "figure(1)" anymore .. so everytime I run my code a new figure is made (unlike if i had the command figure(1), which would cause the new figure 1 to replace the old figure 1 everytime the code is rerun). Does anyone know a way around this ??
>
> second, I don't know if the same is happening to you but my bars are not spread out accorss the entire abscissa ... they're all squished into the left side.  Changing the width by the command bar(differences,width) does not help either.. it just changes the widths of the bars, but doesn't spread them out.  How can i FORCE matlab to spread them (although it should not need forcing in the first place) ???
>
> thanks
> xoxo

As long as you don't close the figure, you can do this:
a = figure('Name','Temp','Units','Normalized','Position',[0 0 1 1]);
figure(a)

If you close the figure, it's 'Position' will be reset, but it will
still only call that one figure...
I hope this helps?

I don't know off the top of my head how to help with the bars,
however. Good luck!
-Nathan

Subject: two problems with bar graphs

From: Juliette Salexa

Date: 7 Jul, 2009 22:42:01

Message: 4 of 8

Thanks Bruno and Nathan, both of those suggestions worked well.

Is the problem with the spacing of the bars only happening on my screen or do you (or anyone else) see it too ??

I also have another (sigh) problems here..
In this extented verison of the original code:
----
fullscreen=get(0,'ScreenSize');
figure('Position',[0,-50 fullscreen(3),fullscreen(4)])
for i=1:25
    subplot(5,5,i)
    differences=rand(1,6) ;labels={'CG','AT','GA','GT','CA','CT'};
    bar(differences);set(gca,'XTickLabel',labels);
    xlabel('$LABEL$','Interpreter','latex','FontSize',10);
    title('TITLE');
end
---
I'm not sure if this happens on your screen, but my xlabels and titles are overlapping .. and yet there's so much blank space at the top and bottom of the entire figure .. I'd like if matlab spread things out better automatically ... or maybe this is just happening on my screen ??

ANy feedback would be very appreciated.

Subject: two problems with bar graphs

From: Nathan

Date: 7 Jul, 2009 22:51:08

Message: 5 of 8

On Jul 7, 3:42 pm, "Juliette Salexa" <juliette.physic...@gmail.com>
wrote:
> Thanks Bruno and Nathan, both of those suggestions worked well.
>
> Is the problem with the spacing of the bars only happening on my screen or do you (or anyone else) see it too ??
>
> I also have another (sigh) problems here..
> In this extented verison of the original code:
> ----
> fullscreen=get(0,'ScreenSize');
> figure('Position',[0,-50 fullscreen(3),fullscreen(4)])
> for i=1:25
>     subplot(5,5,i)
>     differences=rand(1,6) ;labels={'CG','AT','GA','GT','CA','CT'};
>     bar(differences);set(gca,'XTickLabel',labels);
>     xlabel('$LABEL$','Interpreter','latex','FontSize',10);
>     title('TITLE');
> end
> ---
> I'm not sure if this happens on your screen, but my xlabels and titles are overlapping .. and  yet there's so much blank space at the top and bottom of the entire figure .. I'd like if matlab spread things out better automatically ... or maybe this is just happening on my screen ??
>
> ANy feedback would be very appreciated.

It might be happening only on your screen : |
It looks nicely spread out to me.
http://lh5.ggpht.com/_-PiQE3WZBsQ/SlPQoBmxiKI/AAAAAAAACJo/3207DxB12yQ/s720/untitled.jpg

I'm running r2009a right now.

-Nathan

Subject: two problems with bar graphs

From: Juliette Salexa

Date: 7 Jul, 2009 23:29:01

Message: 6 of 8

Thank you Nathan,

Your figure seems to have the same problem as mine in terms of the bars not being spread accross the abscissa.. if anyone on this forum knows how to fix this please let me know!

As for the spacing of the subplots, yours looks much nicer than mine.. I figured out how to fix it though.. by going to tools->align distribute tool .. and manually figuring out what looked best.

 I was going to put up the reverse-generated m-file in case anyone on this forum wanted to know how to do it from the m-file .. but the code's not so clean, so I'm not sure if it's much help.

Thanks again.

Subject: two problems with bar graphs

From: Juliette Salexa

Date: 9 Jul, 2009 22:17:01

Message: 7 of 8

in the following code:

for i=1:25
   subplot(5,5,i)
   differences=rand(1,6) ;labels={'CG','AT','GA','GT','CA','CT'};
   bar(differences);set(gca,'XTickLabel',labels);
   xlabel('$LABEL$','Interpreter','latex','FontSize',10);
   title('TITLE');
   set(gca,'xlim',[0.5 6.5])
end
-----------
the command: set(gca,'xlim',[0.5 6.5]) seems to do the trick to spread out the bars.

Thanks to everyone that helped.

Subject: two problems with bar graphs

From: Alan B

Date: 9 Jul, 2009 22:55:19

Message: 8 of 8

"Juliette Salexa" <juliette.physicist@gmail.com> wrote in message <h35q8t$9mb$1@fred.mathworks.com>...
> in the following code:
>
> for i=1:25
> subplot(5,5,i)
> differences=rand(1,6) ;labels={'CG','AT','GA','GT','CA','CT'};
> bar(differences);set(gca,'XTickLabel',labels);
> xlabel('$LABEL$','Interpreter','latex','FontSize',10);
> title('TITLE');
> set(gca,'xlim',[0.5 6.5])
> end
> -----------
> the command: set(gca,'xlim',[0.5 6.5]) seems to do the trick to spread out the bars.
>
> Thanks to everyone that helped.

You can use "axis tight" to have matlab figure out the best axis limits. Otherwise, it defaults to round numbers, which is sometimes annoying.

Axes positions within the figure can also be set via code (set(gca,'position',[0 0 .2 .2]) for example), rather than through the GUI. I wrote a function called subplot2 for myself that works just like subplot, except it actually fills the figure space instead of leaving almost 50% of the figure window unused. A similar function on the file exchange lets you specify spacings (I haven't used this):
http://www.mathworks.com/matlabcentral/fileexchange/3696

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
fullscreen Sprinceana 22 Aug, 2009 05:29:52
get Sprinceana 22 Aug, 2009 05:29:41
gca Sprinceana 22 Aug, 2009 05:29:41
subplot Sprinceana 22 Aug, 2009 05:29:41
set Sprinceana 22 Aug, 2009 05:29:41
bar graphs Sprinceana 22 Aug, 2009 05:29:29
rssFeed for this Thread

Contact us at files@mathworks.com