Got Questions? Get Answers.
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:
Defining both axis(x,y) in bar3(x,Y) graphs

Subject: Defining both axis(x,y) in bar3(x,Y) graphs

From: Baha Kuzu

Date: 2 Sep, 2011 17:05:14

Message: 1 of 4

Hi everyone, I would like to define both axis of a 3d bar graph. Let's say I have a 3x5 matrix Y, and if I say bar3(Y), this locates Y values in z direction as their own values, but in x and y direction, these values are located as their index number x=1,2,3 & y=1,2,3,4,5. I can define x direction with bar3(x,Y), but what about y direction? Anybody please help?

Baha

Subject: Defining both axis(x,y) in bar3(x,Y) graphs

From: Baha Kuzu

Date: 3 Sep, 2011 03:42:10

Message: 2 of 4

I finally figured out that tedious and 'dead easy' thing, again in a dead
easy way. You will probably say 'what the ...?' I spent a couple
of hours on the web and by asking friends who are expert in matlab but didn't know how to do it. Finally, I accidentally found something that I can use for my bar3 graph when I was looking for something else. Here it is:

 bar3(what ever your data is ... )
 set(gca,'XTickLabel',{'4';'6';'9'}) % for x direction; you can write what ever you want
                                                    % even letter like 'six'
 set(gca,'YTickLabel',{'two';'five';'seven'}) % for y direction
% and even for z direction
 set(gca,'ZTickLabel',{'One';'Two';'Three';'Four'})

This is Ok for my problem. I hope, this helps for your works if needed.
__
Baha

Subject: Defining both axis(x,y) in bar3(x,Y) graphs

From: Caner Gocmen

Date: 22 Aug, 2012 02:26:15

Message: 3 of 4

Thank you very much! It's very helpful.

Caner

"Baha Kuzu" <ibaha411@gmail.com> wrote in message <j3s7mi$2kt$1@newscl01ah.mathworks.com>...
> I finally figured out that tedious and 'dead easy' thing, again in a dead
> easy way. You will probably say 'what the ...?' I spent a couple
> of hours on the web and by asking friends who are expert in matlab but didn't know how to do it. Finally, I accidentally found something that I can use for my bar3 graph when I was looking for something else. Here it is:
>
> bar3(what ever your data is ... )
> set(gca,'XTickLabel',{'4';'6';'9'}) % for x direction; you can write what ever you want
> % even letter like 'six'
> set(gca,'YTickLabel',{'two';'five';'seven'}) % for y direction
> % and even for z direction
> set(gca,'ZTickLabel',{'One';'Two';'Three';'Four'})
>
> This is Ok for my problem. I hope, this helps for your works if needed.
> __
> Baha

Subject: Defining both axis(x,y) in bar3(x,Y) graphs

From: Adam

Date: 4 Jan, 2013 07:32:14

Message: 4 of 4

"Baha Kuzu" <ibaha411@gmail.com> wrote in message <j3r2c9$a9u$1@newscl01ah.mathworks.com>...
> Hi everyone, I would like to define both axis of a 3d bar graph. Let's say I have a 3x5 matrix Y, and if I say bar3(Y), this locates Y values in z direction as their own values, but in x and y direction, these values are located as their index number x=1,2,3 & y=1,2,3,4,5. I can define x direction with bar3(x,Y), but what about y direction? Anybody please help?
>
> Baha

Hi,

  I agree it would be nice to be able to define the data for both axes! Instead, I have resorted to the following (for a square array):

    Inverse_Tick_Rate = 8;
    Axes_Tick_Spacing = ceil(This_Array_Size/Inverse_Tick_Rate);
    Middle_Ticks = (1+Axes_Tick_Spacing):Axes_Tick_Spacing:(This_Array_Size-1);
    Detector_Axes_Ticks = [1 Middle_Ticks This_Array_Size];
    set(gca,'XTick',Detector_Axes_Ticks,'YTick',Detector_Axes_Ticks)
    % Now re-enumrate.
    Old_XTickLabel = str2num(get(gca,'XTickLabel'));
    New_XTickLabel = Old_XTickLabel - ceil((This_Array_Size+1)/2);
    set(gca,'XTickLabel',New_XTickLabel)
    Old_YTickLabel = str2num(get(gca,'YTickLabel'));
    New_YTickLabel = Old_YTickLabel - ceil((This_Array_Size+1)/2);
    set(gca,'YTickLabel',New_YTickLabel)

It controls the XTick/YTick locations so that your relabeling doesn't mess up when the user changes the view (3-D) and Matlab would want to change the Ticks if in 'auto' mode. It always numbers the edges, and in between it labels up to 7 times, so the axes labels don't get crowded for large arrays. The offset changes the enumeration range from e.g. (1,32) to (-16,15) or from (1,31) --> (-15,15). Hope that helps!

-Adam

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