1
$\begingroup$

I have two Graphs, which are displayed in a grid. However, there are two issues which I'm not able to solve.

  1. The two horizontal Axis should be on the same height with any labeling description.

  2. The two vertical Axis should have the same height to make it look consistent.

I tried quite a few things but im not able to solve it adequately. Would be great if somebody could help.

list = {1, 2, 3, 3, 4, 4, 5, 5, 5, 6, 7, 8, 9};
labels = {"test", "test", "ape", "exam", "test", "test", "test", 
   "ape", "exam", "test", "ape", "exam", "test"};

p1 = Histogram[list,
   PlotLabel -> Style["Title", Bold],
   AxesLabel -> {"Variable", "Very long Name"},
   ImageSize -> 400];

p2 = BarChart[
   list,
   ChartLabels -> labels,
   PlotLabel -> Style["Very long Title Very long Title ", Bold],
   AxesLabel -> {"Variable", "Impact  long "},
   ImageSize -> 400,
   BarOrigin -> Left];


Labeled[Panel@Grid[{{p1, p2}}],
 Style[" Analysis", "Section"], Top]

Output

$\endgroup$
  • $\begingroup$ What is scale? $\endgroup$ – Carl Woll Apr 28 '18 at 15:44
  • $\begingroup$ It was an old artefact, i adjusted the code but its still the same problem... $\endgroup$ – Silvan Apr 28 '18 at 15:52
2
$\begingroup$

You can force both charts to have the same baseline and the same plot range image size by using the options BaselinePosition->Axis and ImageSize->Automatic->400. For example:

p1 = Histogram[list,
    PlotLabel->Style["Title",Bold],
    AxesLabel->{"Variable","Very long Name"},
    ImageSize->Automatic->400,
    BaselinePosition->Axis
];

p2 = BarChart[list,
    ChartLabels->labels,
    PlotLabel->Style["Very long Title Very long Title ",Bold],
    AxesLabel->{"Variable","Impact  long "},
    ImageSize->Automatic->400,
    BarOrigin->Left,
    BaselinePosition->Axis
];

Labeled[
    Panel @ Grid[{{p1,p2}}],
    Style[" Analysis","Section"],
    Top
]

enter image description here

Unfortunately, BarChart uses a customized y-axis when the BarOrigin is Left, and the customized y-axis doesn't cover the entire plot range, so the two charts appear to have different vertical sizes. One can see this by adding a point at the top left corner of the bar chart's plot range:

Show[p2, Epilog -> Point[Scaled[{0, 1}]]]

enter image description here

If the bar chart y-axis extended to the dot added above, the vertical sizes would appear to be the same.

$\endgroup$

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.