Putting a vertical line in each Histogram using GraphicsGrid












3












$begingroup$


I'm using GraphicsGrid to show several histograms.



In each histogram, I would like to show 2 vertical lines on the 2.5 and 97.5 percentiles. If I had an isolated histogram I would use Line, and Show. However, I have no idea how to proceed with a GraphicsGrid...










share|improve this question











$endgroup$












  • $begingroup$
    Could you just put your isolated-histogram solution in GraphicsGrid? It'd be easier to diagnose with some code...
    $endgroup$
    – Chris K
    Feb 24 at 10:13
















3












$begingroup$


I'm using GraphicsGrid to show several histograms.



In each histogram, I would like to show 2 vertical lines on the 2.5 and 97.5 percentiles. If I had an isolated histogram I would use Line, and Show. However, I have no idea how to proceed with a GraphicsGrid...










share|improve this question











$endgroup$












  • $begingroup$
    Could you just put your isolated-histogram solution in GraphicsGrid? It'd be easier to diagnose with some code...
    $endgroup$
    – Chris K
    Feb 24 at 10:13














3












3








3





$begingroup$


I'm using GraphicsGrid to show several histograms.



In each histogram, I would like to show 2 vertical lines on the 2.5 and 97.5 percentiles. If I had an isolated histogram I would use Line, and Show. However, I have no idea how to proceed with a GraphicsGrid...










share|improve this question











$endgroup$




I'm using GraphicsGrid to show several histograms.



In each histogram, I would like to show 2 vertical lines on the 2.5 and 97.5 percentiles. If I had an isolated histogram I would use Line, and Show. However, I have no idea how to proceed with a GraphicsGrid...







plotting graphics histograms






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 24 at 10:20









m_goldberg

87k872197




87k872197










asked Feb 24 at 9:31









An old man in the sea.An old man in the sea.

1,064819




1,064819












  • $begingroup$
    Could you just put your isolated-histogram solution in GraphicsGrid? It'd be easier to diagnose with some code...
    $endgroup$
    – Chris K
    Feb 24 at 10:13


















  • $begingroup$
    Could you just put your isolated-histogram solution in GraphicsGrid? It'd be easier to diagnose with some code...
    $endgroup$
    – Chris K
    Feb 24 at 10:13
















$begingroup$
Could you just put your isolated-histogram solution in GraphicsGrid? It'd be easier to diagnose with some code...
$endgroup$
– Chris K
Feb 24 at 10:13




$begingroup$
Could you just put your isolated-histogram solution in GraphicsGrid? It'd be easier to diagnose with some code...
$endgroup$
– Chris K
Feb 24 at 10:13










2 Answers
2






active

oldest

votes


















3












$begingroup$

You can use GridLines combined with the option Method ->{"GridLinesInFront" -> True}:



SeedRandom[1]
{data1, data2} = RandomVariate[NormalDistribution[#, 1], 500] & /@ {2, 4};
GraphicsGrid[{Histogram[#, ImageSize -> 300,
GridLines -> {Thread[{Quantile[#, {.025, .975}],
Directive[Opacity[1], Thick, #] & /@ {Red, Blue}}], None},
Method -> {"GridLinesInFront" -> True}] & /@ {data1, data2}}]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
    $endgroup$
    – Eric William Smith
    Feb 24 at 13:21






  • 1




    $begingroup$
    Than you @Eric. Done.
    $endgroup$
    – kglr
    Feb 24 at 13:42










  • $begingroup$
    Many thanks for the answer. ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:01










  • $begingroup$
    @Anoldmaninthesea., myt pleasure. Thank you for the accept.
    $endgroup$
    – kglr
    Feb 24 at 17:20



















2












$begingroup$

Combining two sets of graphics objects with Show in a graphics grid is not difficult as long as the sets are compatible. That means, at least, all the objects in both lists should be plotted in the same coordinate system and have the same image size.



Here is an example using some graphics I contrived.



Draw random group of $n$ circles



circles[n_] :=
Module[{r, cntr},
r := RandomReal[.25];
cntr := RandomReal[1, {2}];
Graphics[
Table[{EdgeForm[Black], Hue[RandomReal], Disk[cntr, r]}, n],
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Draw two random vertical lines with the left one red and the right one blue.



lines :=
Module[{lf, rt},
lf := With[{x = RandomReal[.48]}, {Red, Line[{{x, 0}, {x, 1}}]}];
rt := With[{x = RandomReal[{.52, 1}]}, {Blue, Line[{{x, 0}, {x, 1}}]}];
Graphics[{lf, rt},
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Now the following simple function will combined any two lists of graphics that are compatible in sense mentioned in the preamble to this answer. The rather elaborate argument patterns on the lefthand side of the SetDelayed expression represent my attempt to enforce the compatibility of the arguments.



makeGrid[g1 : {_Graphics ..}, g2 : {_Graphics ..}, rows_Integer /; rows > 0] /; 
Length[g1] == Length[g2] && Mod[Length[g1], rows] == 0 :=
GraphicsGrid @ Apply[Show, Partition[Transpose[{g1, g2}], rows], {2}]


So let's make a 4 x 4 graphics grid from a list of four circles groups and a list of four pairs of vertical lines.



SeedRandom[4];
makeGrid[Table[circles[8], 4], Table[lines, 4], 2]


grid






share|improve this answer











$endgroup$













  • $begingroup$
    many thanks for the answer ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:02











Your Answer





StackExchange.ifUsing("editor", function () {
return StackExchange.using("mathjaxEditing", function () {
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
});
});
}, "mathjax-editing");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "387"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192106%2fputting-a-vertical-line-in-each-histogram-using-graphicsgrid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









3












$begingroup$

You can use GridLines combined with the option Method ->{"GridLinesInFront" -> True}:



SeedRandom[1]
{data1, data2} = RandomVariate[NormalDistribution[#, 1], 500] & /@ {2, 4};
GraphicsGrid[{Histogram[#, ImageSize -> 300,
GridLines -> {Thread[{Quantile[#, {.025, .975}],
Directive[Opacity[1], Thick, #] & /@ {Red, Blue}}], None},
Method -> {"GridLinesInFront" -> True}] & /@ {data1, data2}}]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
    $endgroup$
    – Eric William Smith
    Feb 24 at 13:21






  • 1




    $begingroup$
    Than you @Eric. Done.
    $endgroup$
    – kglr
    Feb 24 at 13:42










  • $begingroup$
    Many thanks for the answer. ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:01










  • $begingroup$
    @Anoldmaninthesea., myt pleasure. Thank you for the accept.
    $endgroup$
    – kglr
    Feb 24 at 17:20
















3












$begingroup$

You can use GridLines combined with the option Method ->{"GridLinesInFront" -> True}:



SeedRandom[1]
{data1, data2} = RandomVariate[NormalDistribution[#, 1], 500] & /@ {2, 4};
GraphicsGrid[{Histogram[#, ImageSize -> 300,
GridLines -> {Thread[{Quantile[#, {.025, .975}],
Directive[Opacity[1], Thick, #] & /@ {Red, Blue}}], None},
Method -> {"GridLinesInFront" -> True}] & /@ {data1, data2}}]


enter image description here






share|improve this answer











$endgroup$













  • $begingroup$
    Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
    $endgroup$
    – Eric William Smith
    Feb 24 at 13:21






  • 1




    $begingroup$
    Than you @Eric. Done.
    $endgroup$
    – kglr
    Feb 24 at 13:42










  • $begingroup$
    Many thanks for the answer. ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:01










  • $begingroup$
    @Anoldmaninthesea., myt pleasure. Thank you for the accept.
    $endgroup$
    – kglr
    Feb 24 at 17:20














3












3








3





$begingroup$

You can use GridLines combined with the option Method ->{"GridLinesInFront" -> True}:



SeedRandom[1]
{data1, data2} = RandomVariate[NormalDistribution[#, 1], 500] & /@ {2, 4};
GraphicsGrid[{Histogram[#, ImageSize -> 300,
GridLines -> {Thread[{Quantile[#, {.025, .975}],
Directive[Opacity[1], Thick, #] & /@ {Red, Blue}}], None},
Method -> {"GridLinesInFront" -> True}] & /@ {data1, data2}}]


enter image description here






share|improve this answer











$endgroup$



You can use GridLines combined with the option Method ->{"GridLinesInFront" -> True}:



SeedRandom[1]
{data1, data2} = RandomVariate[NormalDistribution[#, 1], 500] & /@ {2, 4};
GraphicsGrid[{Histogram[#, ImageSize -> 300,
GridLines -> {Thread[{Quantile[#, {.025, .975}],
Directive[Opacity[1], Thick, #] & /@ {Red, Blue}}], None},
Method -> {"GridLinesInFront" -> True}] & /@ {data1, data2}}]


enter image description here







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 24 at 13:42

























answered Feb 24 at 11:02









kglrkglr

186k10203422




186k10203422












  • $begingroup$
    Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
    $endgroup$
    – Eric William Smith
    Feb 24 at 13:21






  • 1




    $begingroup$
    Than you @Eric. Done.
    $endgroup$
    – kglr
    Feb 24 at 13:42










  • $begingroup$
    Many thanks for the answer. ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:01










  • $begingroup$
    @Anoldmaninthesea., myt pleasure. Thank you for the accept.
    $endgroup$
    – kglr
    Feb 24 at 17:20


















  • $begingroup$
    Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
    $endgroup$
    – Eric William Smith
    Feb 24 at 13:21






  • 1




    $begingroup$
    Than you @Eric. Done.
    $endgroup$
    – kglr
    Feb 24 at 13:42










  • $begingroup$
    Many thanks for the answer. ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:01










  • $begingroup$
    @Anoldmaninthesea., myt pleasure. Thank you for the accept.
    $endgroup$
    – kglr
    Feb 24 at 17:20
















$begingroup$
Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
$endgroup$
– Eric William Smith
Feb 24 at 13:21




$begingroup$
Do you want to edit this so it's using {0.025, .975} not {0.25, .975}?
$endgroup$
– Eric William Smith
Feb 24 at 13:21




1




1




$begingroup$
Than you @Eric. Done.
$endgroup$
– kglr
Feb 24 at 13:42




$begingroup$
Than you @Eric. Done.
$endgroup$
– kglr
Feb 24 at 13:42












$begingroup$
Many thanks for the answer. ;)
$endgroup$
– An old man in the sea.
Feb 24 at 16:01




$begingroup$
Many thanks for the answer. ;)
$endgroup$
– An old man in the sea.
Feb 24 at 16:01












$begingroup$
@Anoldmaninthesea., myt pleasure. Thank you for the accept.
$endgroup$
– kglr
Feb 24 at 17:20




$begingroup$
@Anoldmaninthesea., myt pleasure. Thank you for the accept.
$endgroup$
– kglr
Feb 24 at 17:20











2












$begingroup$

Combining two sets of graphics objects with Show in a graphics grid is not difficult as long as the sets are compatible. That means, at least, all the objects in both lists should be plotted in the same coordinate system and have the same image size.



Here is an example using some graphics I contrived.



Draw random group of $n$ circles



circles[n_] :=
Module[{r, cntr},
r := RandomReal[.25];
cntr := RandomReal[1, {2}];
Graphics[
Table[{EdgeForm[Black], Hue[RandomReal], Disk[cntr, r]}, n],
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Draw two random vertical lines with the left one red and the right one blue.



lines :=
Module[{lf, rt},
lf := With[{x = RandomReal[.48]}, {Red, Line[{{x, 0}, {x, 1}}]}];
rt := With[{x = RandomReal[{.52, 1}]}, {Blue, Line[{{x, 0}, {x, 1}}]}];
Graphics[{lf, rt},
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Now the following simple function will combined any two lists of graphics that are compatible in sense mentioned in the preamble to this answer. The rather elaborate argument patterns on the lefthand side of the SetDelayed expression represent my attempt to enforce the compatibility of the arguments.



makeGrid[g1 : {_Graphics ..}, g2 : {_Graphics ..}, rows_Integer /; rows > 0] /; 
Length[g1] == Length[g2] && Mod[Length[g1], rows] == 0 :=
GraphicsGrid @ Apply[Show, Partition[Transpose[{g1, g2}], rows], {2}]


So let's make a 4 x 4 graphics grid from a list of four circles groups and a list of four pairs of vertical lines.



SeedRandom[4];
makeGrid[Table[circles[8], 4], Table[lines, 4], 2]


grid






share|improve this answer











$endgroup$













  • $begingroup$
    many thanks for the answer ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:02
















2












$begingroup$

Combining two sets of graphics objects with Show in a graphics grid is not difficult as long as the sets are compatible. That means, at least, all the objects in both lists should be plotted in the same coordinate system and have the same image size.



Here is an example using some graphics I contrived.



Draw random group of $n$ circles



circles[n_] :=
Module[{r, cntr},
r := RandomReal[.25];
cntr := RandomReal[1, {2}];
Graphics[
Table[{EdgeForm[Black], Hue[RandomReal], Disk[cntr, r]}, n],
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Draw two random vertical lines with the left one red and the right one blue.



lines :=
Module[{lf, rt},
lf := With[{x = RandomReal[.48]}, {Red, Line[{{x, 0}, {x, 1}}]}];
rt := With[{x = RandomReal[{.52, 1}]}, {Blue, Line[{{x, 0}, {x, 1}}]}];
Graphics[{lf, rt},
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Now the following simple function will combined any two lists of graphics that are compatible in sense mentioned in the preamble to this answer. The rather elaborate argument patterns on the lefthand side of the SetDelayed expression represent my attempt to enforce the compatibility of the arguments.



makeGrid[g1 : {_Graphics ..}, g2 : {_Graphics ..}, rows_Integer /; rows > 0] /; 
Length[g1] == Length[g2] && Mod[Length[g1], rows] == 0 :=
GraphicsGrid @ Apply[Show, Partition[Transpose[{g1, g2}], rows], {2}]


So let's make a 4 x 4 graphics grid from a list of four circles groups and a list of four pairs of vertical lines.



SeedRandom[4];
makeGrid[Table[circles[8], 4], Table[lines, 4], 2]


grid






share|improve this answer











$endgroup$













  • $begingroup$
    many thanks for the answer ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:02














2












2








2





$begingroup$

Combining two sets of graphics objects with Show in a graphics grid is not difficult as long as the sets are compatible. That means, at least, all the objects in both lists should be plotted in the same coordinate system and have the same image size.



Here is an example using some graphics I contrived.



Draw random group of $n$ circles



circles[n_] :=
Module[{r, cntr},
r := RandomReal[.25];
cntr := RandomReal[1, {2}];
Graphics[
Table[{EdgeForm[Black], Hue[RandomReal], Disk[cntr, r]}, n],
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Draw two random vertical lines with the left one red and the right one blue.



lines :=
Module[{lf, rt},
lf := With[{x = RandomReal[.48]}, {Red, Line[{{x, 0}, {x, 1}}]}];
rt := With[{x = RandomReal[{.52, 1}]}, {Blue, Line[{{x, 0}, {x, 1}}]}];
Graphics[{lf, rt},
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Now the following simple function will combined any two lists of graphics that are compatible in sense mentioned in the preamble to this answer. The rather elaborate argument patterns on the lefthand side of the SetDelayed expression represent my attempt to enforce the compatibility of the arguments.



makeGrid[g1 : {_Graphics ..}, g2 : {_Graphics ..}, rows_Integer /; rows > 0] /; 
Length[g1] == Length[g2] && Mod[Length[g1], rows] == 0 :=
GraphicsGrid @ Apply[Show, Partition[Transpose[{g1, g2}], rows], {2}]


So let's make a 4 x 4 graphics grid from a list of four circles groups and a list of four pairs of vertical lines.



SeedRandom[4];
makeGrid[Table[circles[8], 4], Table[lines, 4], 2]


grid






share|improve this answer











$endgroup$



Combining two sets of graphics objects with Show in a graphics grid is not difficult as long as the sets are compatible. That means, at least, all the objects in both lists should be plotted in the same coordinate system and have the same image size.



Here is an example using some graphics I contrived.



Draw random group of $n$ circles



circles[n_] :=
Module[{r, cntr},
r := RandomReal[.25];
cntr := RandomReal[1, {2}];
Graphics[
Table[{EdgeForm[Black], Hue[RandomReal], Disk[cntr, r]}, n],
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Draw two random vertical lines with the left one red and the right one blue.



lines :=
Module[{lf, rt},
lf := With[{x = RandomReal[.48]}, {Red, Line[{{x, 0}, {x, 1}}]}];
rt := With[{x = RandomReal[{.52, 1}]}, {Blue, Line[{{x, 0}, {x, 1}}]}];
Graphics[{lf, rt},
PlotRange -> {{0, 1}, {0, 1}},
PlotRangeClipping -> True,
Frame -> True]]


Now the following simple function will combined any two lists of graphics that are compatible in sense mentioned in the preamble to this answer. The rather elaborate argument patterns on the lefthand side of the SetDelayed expression represent my attempt to enforce the compatibility of the arguments.



makeGrid[g1 : {_Graphics ..}, g2 : {_Graphics ..}, rows_Integer /; rows > 0] /; 
Length[g1] == Length[g2] && Mod[Length[g1], rows] == 0 :=
GraphicsGrid @ Apply[Show, Partition[Transpose[{g1, g2}], rows], {2}]


So let's make a 4 x 4 graphics grid from a list of four circles groups and a list of four pairs of vertical lines.



SeedRandom[4];
makeGrid[Table[circles[8], 4], Table[lines, 4], 2]


grid







share|improve this answer














share|improve this answer



share|improve this answer








edited Feb 24 at 12:40

























answered Feb 24 at 12:30









m_goldbergm_goldberg

87k872197




87k872197












  • $begingroup$
    many thanks for the answer ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:02


















  • $begingroup$
    many thanks for the answer ;)
    $endgroup$
    – An old man in the sea.
    Feb 24 at 16:02
















$begingroup$
many thanks for the answer ;)
$endgroup$
– An old man in the sea.
Feb 24 at 16:02




$begingroup$
many thanks for the answer ;)
$endgroup$
– An old man in the sea.
Feb 24 at 16:02


















draft saved

draft discarded




















































Thanks for contributing an answer to Mathematica Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


Use MathJax to format equations. MathJax reference.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f192106%2fputting-a-vertical-line-in-each-histogram-using-graphicsgrid%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?