I need to specify the length of the tick marks on the x axis in a BarChart plot:

 {{1, -2}, {2, -3}, {3, -4}},
 BarSpacing -> {0, 1},
 Axes -> True,
 Ticks -> None,
 TicksStyle -> Red] 

enter image description here

I can modify the style settings for the tick marks on the x axis. However, I found no possibility to remove (see code above with the option Ticks -> None ) nor to give the specified positions of the tick marks.

In particular, I want to specify the lengths in the positive and negative directions, like described in the Ticks description in the documentation center.

  • 1
    $\begingroup$ maybe this will help? mathematica.stackexchange.com/questions/16749/… $\endgroup$ – Pinguin Dirk Mar 27 '13 at 20:13
  • $\begingroup$ Unfortunately not, since the ticks are manipulated on the "bar height" axis. I'm looking for a way to manipulate the ticks on the "bar number" axis. $\endgroup$ – Robinaut Mar 28 '13 at 6:05
  • 1
    $\begingroup$ Seems to be a bug of MMA 9, in MMA 8 frame ticks can be manipulated as expected... $\endgroup$ – Robinaut Mar 28 '13 at 6:19

Currently, I cannot check how this worked in version 8, but in version 9, me too was struggling with those ticks. Possibly there is direct way, I'd be happy to see that. Or as you suggest, maybe it is a bug, I cannot tell.

NOTE: for removing the ticks, see the link I posted (Opacity[0] seems to do the trick)

Though, it makes sense to me that in a bar chart the ticks on the "bar number" axis, as you call it, are not very relevant (as there is no scale, I guess).

Still, here's a possible workaround, using standard charting functions & options, maybe that will help you...

My plan was to use ListLinePlot, as there we do have a fully functional x-axis. Thus:

points = {1, -2, 2, -3, 3, -4}

are the "bars" we want to plot. As in your example, we partition in groups of two bars each and fill with zeros between groups (and prepend, append zero) so that ListLinePlot looks better:

pts = Flatten@
      Riffle[ConstantArray[0, (Length@points)/2 + 1], points~Partition~2]

In order to have more control where the bars are (we could use standard ListPlot option: " assumed to correspond to x coordinates 1, 2,...", we can for instance use:

MapIndexed[{First[#2] - 1, #} &, pts]

to get

{{0, 0}, {1, 1}, {2, -2}, {3, 0}, {4, 2}, {5, -3}, {6, 0}, {7, 3}, {8, -4}, {9, 0}}

and we are ready to plot:

ListLinePlot[MapIndexed[{First[#2] - 1, #} &, pts], 
    InterpolationOrder -> 0, Filling -> Axis, 
    FillingStyle -> {LightRed, LightGreen}, PlotStyle -> {Thin, Gray}, 
    AxesOrigin -> {0.5, 0}, 
    Ticks -> {{
             {1.5, "Max 1", {0, 0.4}, LightGreen}, 
             {2.5, "Min 1", {0, 0.4}, LightRed}, 
             {4.5, "Max 2", {0, 0.4}, LightGreen}, 
             {5.5, "Min 2", {0, 0.4}, LightRed}, 
             {7.5, "Max 3", {0, 0.4}, LightGreen}, 
             {8.5, "Min 3", {0, 0.4}, LightRed}}, None}]

which looks like:

enter image description here

  • $\begingroup$ Nice workaround! Since I'm not allowed to use transparencies in my PDF document I'll try ListLinePlot for my visualization... $\endgroup$ – Robinaut Mar 28 '13 at 12:24
  • $\begingroup$ glad that helps - (or just use v8 if it works there :) ). Depending on the data other charting types might be helpful too (RectangleChart, ListPlot,...) but as I had problems understanding why you might want to modify ticks on the "x-axis", I came up with this idea in v9... $\endgroup$ – Pinguin Dirk Mar 28 '13 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.