Message Boards Message Boards

0
|
4822 Views
|
4 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Highlight the graph between points in histogram with intervals

Posted 10 years ago

Hello, can someone please advise me how I should do this graph:

data = {13, 13.1, 13.2, 13.3, 14.5, 12.6, 11.3, 12.1, 10.5, 10.3, 10.7, 10.1}
Histogram[data, {Min[data], Max[data], 0.3}]
point1 = 12
point2 = 13

I have entered data and histogram. I have awarded points "point1 point2" I need to highlight the graph between points.

I need this: enter image description here

Thank you for the advice :) :) :)

POSTED BY: martin martin
4 Replies
Posted 10 years ago

This should work:

col1 = RGBColor[0.987, 0.807, 0.495];
col2 = Lighter@Blue;
f[{{xmin_, xmax_}, {ymin_, ymax_}}, ___] :=
 Piecewise[{
   {{col1, Rectangle[{xmin, ymin}, {xmax, ymax}]}, 
    xmin >= point2 || xmax <= point1},
   {{col2, Rectangle[{xmin, ymin}, {xmax, ymax}]}, 
    xmin >= point1 && xmax <= point2},
   {{col1, Rectangle[{xmin, ymin}, {point1, ymax}], col2, 
     Rectangle[{point1, ymin}, {point2, ymax}], col1, 
     Rectangle[{point2, ymin}, {xmax, ymax}]}, 
    xmin < point1 && xmax > point2},
   {{col1, Rectangle[{xmin, ymin}, {point1, ymax}], col2, 
     Rectangle[{point1, ymin}, {xmax, ymax}]}, xmin < point1},
   {{col2, Rectangle[{xmin, ymin}, {point2, ymax}], col1, 
     Rectangle[{point2, ymin}, {xmax, ymax}]}, xmax > point2}
   }]
Histogram[data, {Min[data], Max[data], 0.3}, 
 ChartElementFunction -> f]

enter image description here

POSTED BY: qwerty
POSTED BY: martin martin

Thank you for answer :) and it is only paint the picture chart? Or that Mathematica can not.enter image description here

POSTED BY: martin martin

Hi Martin, a quick and dirty way could be this:

data = {13, 13.1, 13.2, 13.3, 14.5, 12.6, 11.3, 12.1, 10.5, 10.3, 10.7, 10.1} ; 
point1 = 12; point2 = 13;
Show[Histogram[data, {Min[data], Max[data], 0.3}],
 Graphics[{Blue, Opacity[.5], Rectangle[{point1, 0}, {point2, 1.3}]}]]

giving:

enter image description here

Regards -- Henrik

POSTED BY: Henrik Schachner
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract