labels in categorical bar graph

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

labels in categorical bar graph

Raag Saluja
Hi! 

I tried making a bar graph with categorical data. However, the labels of the categories are not coming below the bars. Can you please help?

This is the code I used:

P = -2,920,000 -2,936,000 -2,935,000 -2,937,000 -2,939,000 -2,938,000

bar(P)

set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'});


PFA a screenshot of the output.

Thank you and regards,
Raag Saluja
Research Scholar
Department of Zoology
Faculty of Science
Dayalbagh Educational Institute
INDIA



Screenshot 2019-10-30 at 1.31.38 PM.png (29K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: labels in categorical bar graph

BGreen
On Thu, Oct 31, 2019 at 3:12 AM Raag Saluja <[hidden email]> wrote:
Hi! 

I tried making a bar graph with categorical data. However, the labels of the categories are not coming below the bars. Can you please help?

This is the code I used:

P = -2,920,000 -2,936,000 -2,935,000 -2,937,000 -2,939,000 -2,938,000

bar(P)

set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'});


PFA a screenshot of the output.

Thank you and regards,
Raag Saluja
Research Scholar
Department of Zoology
Faculty of Science
Dayalbagh Educational Institute
INDIA

This is what you want:

P = [-2920000 -2936000 -2935000 -2937000 -2939000 -2938000];
bar(P)
set(gca,"xticklabel",{'1JFF','\alpha 1a\beta II','\alpha 1a\betaIII','\alpha 1b\beta II','\alpha 1b\beta III','\alpha 8\beta 8'});
 
Commas separate elements in arrays, or function arguments, or things like that. They should never be used to mark thousands, millions, etc. in code. If you check the axes on your graph, you'll notice that the tall bars are positive, whereas the numbers you entered are positive. You can also see a small negative bar for each -2. The spaces are from the 000 entries, and the tall bars are form the 9xx entries.


Reply | Threaded
Open this post in threaded view
|

Re: labels in categorical bar graph

mmuetzel
In reply to this post by Raag Saluja
Am 31. Oktober 2019 um 08:11 Uhr schrieb "Raag Saluja":
> Hi! 

> I tried making a bar graph with categorical data. However, the labels of the categories are not coming below the bars. Can you please help?
>  
> This is the code I used:
> P = -2,920,000 -2,936,000 -2,935,000 -2,937,000 -2,939,000 -2,938,000
> bar(P)
> set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'});
 
Try also setting a tick at each x value:
set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'}, "XTick", 1:numel(P));

Markus



Reply | Threaded
Open this post in threaded view
|

Re: labels in categorical bar graph

Pantxo
mmuetzel wrote

> Am 31. Oktober 2019 um 08:11 Uhr schrieb "Raag Saluja":
>> Hi! 
>> 
>> I tried making a bar graph with categorical data. However, the labels of
>> the categories are not coming below the bars. Can you please help?
>>  
>> This is the code I used:
>> P = -2,920,000 -2,936,000 -2,935,000 -2,937,000 -2,939,000 -2,938,000
>> bar(P)
>> set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII',
>> 'α8β8'});
>  
> Try also setting a tick at each x value:
> set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII',
> 'α8β8'}, "XTick", 1:numel(P));
>
> Markus

I think this question was asked and answered twice
(https://octave.1599824.n4.nabble.com/xticklables-td4694366.html). OP,
please try to not do multiple posts for the same question.

Pantxo



--
Sent from: https://octave.1599824.n4.nabble.com/Octave-General-f1599825.html


Reply | Threaded
Open this post in threaded view
|

Re: labels in categorical bar graph

Raag Saluja
In reply to this post by mmuetzel
Thank you so much! Can you please help me with one more thing?
I was making a subplots. How do I get the (a), (b), (c).... labels of the various subplots? So later I can refer to them as Fig X (a) etc.

Thank you and sorry for the bother!
Regards,
Raag

On Thu, Oct 31, 2019 at 9:28 PM "Markus Mützel" <[hidden email]> wrote:
Am 31. Oktober 2019 um 08:11 Uhr schrieb "Raag Saluja":
> Hi! 

> I tried making a bar graph with categorical data. However, the labels of the categories are not coming below the bars. Can you please help?
>  
> This is the code I used:
> P = -2,920,000 -2,936,000 -2,935,000 -2,937,000 -2,939,000 -2,938,000
> bar(P)
> set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'});
 
Try also setting a tick at each x value:
set(gca,"xticklabel",{'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'}, "XTick", 1:numel(P));

Markus



Reply | Threaded
Open this post in threaded view
|

Re: labels in categorical bar graph

mmuetzel
Am 01. November 2019 um 07:38 Uhr schrieb "Raag Saluja":
> Thank you so much! Can you please help me with one more thing?
> I was making a subplots. How do I get the (a), (b), (c).... labels of the various subplots? So later I can refer to them as Fig X (a) etc.

The "subplot" function returns the handle to the corresponding axes. So you would use that handle - instead of the handle to the currently active axes returned by "gca". E.g.:
hax1 = subplot(3,1,1);
hax2 = subplot(3,1,2);
hax3 = subplot(3,1,3);

Now to change the axes of - let's say - the subplot in the middle:
set(hax2, "xticklabel", {'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'}, "XTick", 1:numel(P));

Hope this answers what you have asked...

Markus


Reply | Threaded
Open this post in threaded view
|

Re: labels in categorical bar graph

BGreen

On Fri, Nov 1, 2019 at 6:40 AM "Markus Mützel" <[hidden email]> wrote:
Am 01. November 2019 um 07:38 Uhr schrieb "Raag Saluja":
> Thank you so much! Can you please help me with one more thing?
> I was making a subplots. How do I get the (a), (b), (c).... labels of the various subplots? So later I can refer to them as Fig X (a) etc.

The "subplot" function returns the handle to the corresponding axes. So you would use that handle - instead of the handle to the currently active axes returned by "gca". E.g.:
hax1 = subplot(3,1,1);
hax2 = subplot(3,1,2);
hax3 = subplot(3,1,3);

Now to change the axes of - let's say - the subplot in the middle:
set(hax2, "xticklabel", {'1JFF','α1aβII', 'α1aβIII', 'α1bβII', 'α1bβIII', 'α8β8'}, "XTick", 1:numel(P));

Hope this answers what you have asked...

Markus

Raag,

Try calling something like
 text(-.75,-1.5,"(a)")
right after you make the plot. The "text" function overlays text on the current axes. Enter "doc text" in the command line to find more information about how to tweak its properties, like font size.

- Brett Green