I recently ran a rather time intensive calculation and plotted the results in a histogram by simply called Histogram[data]. However, because of a rather serious error on my part, I recently lost my original data and all I have is the histogram plot.

I need to change the vertical cut-off on the histogram (it will cut off any bars with an event count >= N). I can hover over the bars and read the values, so I know the information is there, but how can I change the value of N for the vertical cutoff?


1 Answer 1

 data = RandomVariate[NormalDistribution[0, 1], 200];
 hh = Histogram[data]

enter image description here

Copy the graphic you have (Ctrl+C) and in a new cell type gr= and paste your graphic (Ctrl+V):

enter image description here

 gr /. RectangleBox[x : {_, _}, y : {y1_, y2_}, z__] :> 
       RectangleBox[x, {y1, Min[y2, 30]}, z]


enter image description here

Update: An alternative approach is to replace the PlotRange and PlotRangePadding options of gr:

 gr /. {HoldPattern[PlotRange -> _] :> PlotRange -> {0, 30},
     HoldPattern[PlotRangePadding -> _] :> PlotRangePadding -> 0}

enter image description here

You can also use Show with PlotRange and PlotRangePadding options:

 Show[gr, PlotRange -> {0, 30}, PlotRangePadding -> 0]

which gives an output identical to the last one.

  • $\begingroup$ I recieve an error saying the FrontEnd 'If is not a graphics primitive or directive. $\endgroup$
    – Nikki
    Dec 24, 2012 at 13:14
  • $\begingroup$ I cannot regenerate the histogram, I only have the graphic. $\endgroup$
    – Nikki
    Dec 24, 2012 at 13:15
  • $\begingroup$ @Nikki, I updated with the answer showing how to use the graphic you have. Regarding the error message in your first comment, I am not getting any error messages (using Windows Vista 64bit, Mathematica Version 9). $\endgroup$
    – kglr
    Dec 24, 2012 at 13:33
  • $\begingroup$ That's effectively what I tried earlier... hmm... does it still work for you if you quit the kernel and then try it? $\endgroup$
    – Nikki
    Dec 24, 2012 at 13:49
  • $\begingroup$ Yes, it does work with a fresh kernel. Just checked that it also works in Version Do you get the same error message when you use the methods on a new histogram? If not, perhaps you can post the FullForm of your graphic to see if there is anything specific that is causing the issue. (To get the FullForm of your graphic, just copy-paste it inside the brackets in FullForm[] in a new cell.) $\endgroup$
    – kglr
    Dec 24, 2012 at 14:09

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.