3
$\begingroup$

How can I Frame a PairedHistogram and manipulate the frame ticks? I want to specify and control the frame ticks in the paired histogram below.

spacez = RandomVariate[PoissonDistribution[11], 1000];
spacem = RandomVariate[PoissonDistribution[11], 1000];
PairedHistogram[spacez, spacem, {1, 11, 1}, PlotRange -> {{All, All}},
  ChartStyle -> {{Red, Blue}}, BaseStyle -> {FontSize -> 24}, 
 AxesStyle -> Thick, BarSpacing -> 0, 
 ColorFunction -> Function[Opacity[0.5]], BarOrigin -> "XAxis"]

enter image description here

$\endgroup$
0

1 Answer 1

2
$\begingroup$

One problem is that PairedHistogram constructs its own axes/ticks, overriding to some extent (and thereby interfereing with) the standard system approach. I don't know why it does this. Ticks seems to be able to be used to relabel the automatically generated ticks (an observation), but the option cannot be used as it can with, say, Plot. Passing a function, for instance, has no effect.

However, one can use Frame. Use the Axes options Frame on. Then you can use FrameTicks to specify ticks. I made a function absSingleTick to reverse the sign of ticks with negative coordinates.

SeedRandom[1];
spacez = RandomVariate[PoissonDistribution[11], 1000];
spacem = RandomVariate[PoissonDistribution[11], 1000];

absSingleTick[{a_, b_}] := {a, Abs[b]};
absSingleTick[t_] := t;

PairedHistogram[spacez, spacem, {1, 11, 1}, PlotRange -> {{All, All}},
  ChartStyle -> {{Red, Blue}}, BaseStyle -> {FontSize -> 24}, 
 BarSpacing -> 0, ColorFunction -> Function[Opacity[0.5]], 
 BarOrigin -> "XAxis",
 Axes -> False, Frame -> True, FrameStyle -> Purple, 
 FrameTicks -> {
   {absSingleTick /@ Charting`FindTicks[{1, 0}, {1, 0}][##] &, Automatic},
   {Charting`FindTicks[{1, 0}, {1, 0}][##] &, Automatic}}
 ]

Mathematica graphics

$\endgroup$
3
  • $\begingroup$ Thank you Michael. That works great for me. $\endgroup$
    – Balaji
    Oct 16, 2013 at 18:37
  • $\begingroup$ Would that work for the first example of the PairedHistogram page? Can't try it right now, but I guess the split x-axis will cause problems. $\endgroup$ Oct 16, 2013 at 21:39
  • $\begingroup$ @SjoerdC.deVries You can remove the gap with BarSpacing -> 0 as the OP does. However, I'm finding that (any) ticks functions for the horizontal frame element generate error messages, when I try the above method on the first PairedHistogram example. :( Bug? $\endgroup$
    – Michael E2
    Oct 17, 2013 at 6:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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