Thread Subject: Inverting a bar chart

Subject: Inverting a bar chart

From: Ryan Utz

Date: 28 Oct, 2009 18:17:11

Message: 1 of 6

Hello all,

I need to make a simple (i.e. bar(x,y)) bar chart where the y-axis is inverted, in other words, bars go down instead of up (though the values are positive), so that the graph looks like columns hanging from the ceiling. Is there any way to tell Matlab to do this? Multiplying all of my y-axis values by -1 does the trick but then the y-axis is incorrectly labeled (i.e. with negative values).

Thanks for any/all help,
Ryan

Subject: Inverting a bar chart

From: Nathan

Date: 28 Oct, 2009 18:24:11

Message: 2 of 6

On Oct 28, 11:17 am, "Ryan Utz" <r...@al.umces.edu> wrote:
> Hello all,
>
> I need to make a simple (i.e. bar(x,y)) bar chart where the y-axis is inverted, in other words, bars go down instead of up (though the values are positive), so that the graph looks like columns hanging from the ceiling. Is there any way to tell Matlab to do this? Multiplying all of my y-axis values by -1 does the trick but then the y-axis is incorrectly labeled (i.e. with negative values).
>
> Thanks for any/all help,
> Ryan

How about you do as you did (multiply your data set by -1), and then
change the ticklabels accordingly?
Ex:
bar(-1*(1:10))
set(gca,'yticklabel',num2str(-1*str2num(get(gca,'yticklabel'))))

-Nathan

Subject: Inverting a bar chart

From: the cyclist

Date: 28 Oct, 2009 18:25:18

Message: 3 of 6

"Ryan Utz" <rutz@al.umces.edu> wrote in message <hca1r7$ove$1@fred.mathworks.com>...
> Hello all,
>
> I need to make a simple (i.e. bar(x,y)) bar chart where the y-axis is inverted, in other words, bars go down instead of up (though the values are positive), so that the graph looks like columns hanging from the ceiling. Is there any way to tell Matlab to do this? Multiplying all of my y-axis values by -1 does the trick but then the y-axis is incorrectly labeled (i.e. with negative values).
>
> Thanks for any/all help,
> Ryan

Not sure if this is the best way, but one way is

>> set(gca,'View',[0 -90])

Normally the View property is [0 90]

Subject: Inverting a bar chart

From: dpb

Date: 28 Oct, 2009 18:20:16

Message: 4 of 6

Ryan Utz wrote:
> Hello all,
>
> I need to make a simple (i.e. bar(x,y)) bar chart where the y-axis is
> inverted, in other words, bars go down instead of up (though the
> values are positive), so that the graph looks like columns hanging
> from the ceiling. Is there any way to tell Matlab to do this?
> Multiplying all of my y-axis values by -1 does the trick but then the
> y-axis is incorrectly labeled (i.e. with negative values).


Not sure about being able to orient that way except as you did but you
can always work around the negative y-axis labels by writing them
explicitly as text.

--

Subject: Inverting a bar chart

From: Richard Quist

Date: 28 Oct, 2009 19:22:43

Message: 5 of 6

Ryan Utz wrote:
> Hello all,
>
> I need to make a simple (i.e. bar(x,y)) bar chart where the y-axis is inverted, in other words, bars go down instead of up (though the values are positive), so that the graph looks like columns hanging from the ceiling. Is there any way to tell Matlab to do this? Multiplying all of my y-axis values by -1 does the trick but then the y-axis is incorrectly labeled (i.e. with negative values).
>
> Thanks for any/all help,
> Ryan

Assuming gca (the current axes) is the axes containing the bar plot:
   set(gca, 'ydir', 'reverse');

--

Richard Quist
Software Developer
The MathWorks, Inc.

Subject: Inverting a bar chart

From: Ryan Utz

Date: 28 Oct, 2009 20:36:19

Message: 6 of 6

Thanks! all of these work, but those suggested by Richard and dpb are the shortest

Tags for this Thread

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.

rssFeed for this Thread
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com