Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridLine on top of a Bar Chart in Mathematica

Is it possible to get a GridLine over a BartChart ? Gridlines draw it under and Mesh does not seem to work with BarChart.

BarChart[{Range[10], Range[10]}, 
         ChartLayout -> "Stacked", 
         GridLines -> {None, {4}}, 
         GridLinesStyle -> Directive[Orange, Thick]]

enter image description here

like image 491
500 Avatar asked Aug 24 '11 14:08

500


2 Answers

This can be done via a method option:

BarChart[{Range[10], Range[10]}, ChartLayout -> "Stacked", 
 GridLines -> {None, {4}}, GridLinesStyle -> Directive[Orange, Thick],
  Method -> {"GridLinesInFront" -> True}]

enter image description here

(this should work for any graphic.)

like image 81
Brett Champion Avatar answered Oct 04 '22 14:10

Brett Champion


Your other option would be to draw the gridline explicitly with Epilog. This would be the solution if you wanted some gridlines (e.g. vertical ones) behind and some in front. I have added some other options in case you don't actually want the gridline to bleed over the axes.

BarChart[{Range[10], Range[10]}, ChartLayout -> "Stacked", 
 Epilog -> {Orange, Thick, Line[{{0, 4}, {3, 4}}]}, 
 PlotRangeClipping -> True, PlotRangePadding -> 0]

enter image description here

like image 31
Verbeia Avatar answered Oct 04 '22 13:10

Verbeia