MathGroup Archive 2000

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: BarChart Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25003] Re: [mg24980] BarChart Question
  • From: "Tomas Garza" <tgarza at mail.internet.com.mx>
  • Date: Fri, 1 Sep 2000 01:09:36 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Steve (com3 at ix.netcom*NOSPAM*.com) wrote:

> I'm hoping someone can show a new/infrequent user of ver 3.0 what he's
> doing wrong and provide a simple solution to my problem.
>
> I'm trying to produce a bar chart with readable x axis tick labels. My
> code is below. Since my xvalues have a maximum value of 1.0, this
> should also be the maximum value of the x axis tick label. The y axis
> labelling seems to be working fine.
>
> If BarChart can't do this, can ListPlot or any of the other built-in
> plot types ?
>
> xvalues=Range[0,1,.01];
> yvalues=2*xvalues;
> ticklabels=Range[0,1,.1];
> plot1=BarChart[Transpose[{yvalues,xvalues}],Ticks->{ticklabels,Automatic}]

Since you want to place the labels at points corresponding to specified bars
in the graph, I suggest you use BarLabels instead of Ticks. E.g., suppose
you have only 20 bars (I presume 100 is too many and in this case I would
rather use some other type of plot) and you want to place the BarLabels at
every other bar:

In[1]:=
<< Graphics`Graphics`
In[2]:=
xvalues = Range[0, 1, 0.05];
yvalues = 2*xvalues;

Now you must "delete" those values you don't want printed by replacing them
with a blank:

In[3]:=
tickvalues = Table[If[OddQ[j], xvalues[[j]], " "], {j, 1, Length[xvalues]}]
Out[3]=
{0, " ", 0.1, " ", 0.2, " ", 0.3, " ", 0.4, " ", 0.5, " ", 0.6, " ", 0.7, "
\
", 0.8, " ", 0.9, " ", 1.}
In[4]:=
plot1 = BarChart[Transpose[{yvalues, xvalues}], BarLabels -> tickvalues]

This will give you the desired result. The problem with using Ticks (which
is a valid option for BarChart) in this case is that the axis in the
BarChart is scaled. But if you still wish to use Ticks, then you can rescale
the position of the ticks:

In[7]:=
b = Transpose[{20*xvalues + 1, tickvalues}]
Out[7]=
{{1, 0}, {2., " "}, {3., 0.1}, {4., " "}, {5., 0.2}, {6., " "}, {7.,
    0.3}, {8., " "}, {9., 0.4}, {10., " "}, {11., 0.5}, {12., " "}, {13.,
    0.6}, {14., " "}, {15., 0.7}, {16., " "}, {17., 0.8}, {18., " "}, {19.,
    0.9}, {20., " "}, {21., 1.}}

In[8]:=
plot2 = BarChart[Transpose[{yvalues, xvalues}], Ticks -> {b, Automatic}]

This will give you the same plot as above. Still, I find the former easier
to use.

Tomas Garza
Mexico City



  • Prev by Date: Re: Line Thicknes in arrows in PlotField
  • Next by Date: Financial Modeling with Mathematica - 12 and 13
  • Previous by thread: Re: BarChart Question
  • Next by thread: Re: Functional or rule-based ...