4
$\begingroup$

Consider the following:

SetOptions[Histogram, BarOrigin -> Left, 
  Frame -> {{True, None}, {True, None}}, FrameTicks -> Automatic];

data1 = {Table[1, {i, 5}], Table[5, {i, 50}], Table[3, {i, 25}], 
   Table[4, {i, 20}]};
data2 = {Table[1, {i, 3}], Table[5, {i, 20}], Table[3, {i, 25}]};
data3 = {Table[1, {i, 3}], Table[5, {i, 20}], Table[4, {i, 15}]};

histo1 = Histogram[data1]
histo2a = Show[Histogram[data1, ChartElements -> None],Histogram[data2]]
histo3a = Show[Histogram[data1, ChartElements -> None],Histogram[data3]]

histo2b = Show[Histogram[data1], Histogram[data2, ChartStyle -> Red]]    
histo3b = Show[Histogram[data1], Histogram[data3, ChartStyle -> Red]]

I would like to use the same frame/coordinate system for histo2a and histo3a as in histo1. histo3b shows how it should be (only without the grey part) and histo2a how it should not be. histo2bin addition shows the disadvantage of the Show[]-approach (one bar exceeds the frame).

Due to the latter, I was trying to extract the FrameTicks-values from histo1 and to use them for Histogram[data2] and Histogram[data3] but neitherOptions[histo1,FrameTicks],AbsoluteOptions[histo1,FrameTicks]norHistogramList[data1]` return help.

Now I would like to use exactly the same frame ticks, which were calculated based on data1 for histo2.

Neither Options[histo1,FrameTicks], AbsoluteOptions[histo1,FrameTicks] or HistogramList[data1] help. Has anyone an idea?

$\endgroup$
4
  • $\begingroup$ So Histogram[data2,{HistogramList[data1][[1]]}] does not do what you want ? $\endgroup$ Mar 24, 2012 at 12:31
  • $\begingroup$ Do you want also the same bins used? $\endgroup$ Mar 24, 2012 at 14:23
  • $\begingroup$ possible duplicate of Retrieving PlotRange form BarChart $\endgroup$
    – rm -rf
    Mar 24, 2012 at 15:33
  • $\begingroup$ No, please see below. $\endgroup$
    – John
    Mar 25, 2012 at 11:48

1 Answer 1

5
$\begingroup$

Perhaps:

SetOptions[Histogram, BarOrigin -> Left, 
  Frame -> {{True, None}, {True, None}}, FrameTicks -> Automatic];

data1 = Table[BesselJ[1, x], {x, 0, 500}];
data2 = Table[BesselJ[1, x], {x, 0, 100}];
GraphicsGrid[{{
   histo1 = Histogram[data1],
   histo2 = Histogram[data2],
   Show[
    Histogram[data2, ChartElements -> None], 
    Histogram[data1, {HistogramList[data2][[1]]}]]}}]

enter image description here

Edit

use just

Show[Histogram[data2, ChartElements -> None], Histogram[data1]]

if you don't want to reuse the same bins:

enter image description here

$\endgroup$
1
  • $\begingroup$ This is almost, what I was looking for, but please take a look at my edit. $\endgroup$
    – John
    Mar 25, 2012 at 15:12

Your Answer

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

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