1
$\begingroup$
g1 = Graphics[{EdgeForm[{Thick, Blue}], FaceForm[], Rectangle[]}, 
   ImageSize -> {400, 400}];

g2 = Graphics[{{EdgeForm[{Dashed, Blue}], FaceForm[], Rectangle[]}, 
    GeometricTransformation[{EdgeForm[{Thick, Blue}], FaceForm[], 
      Rectangle[]}, ShearingMatrix[30 Degree, {1, 0}, {0, 1}]]}, 
   ImageSize -> {400, 400}];

But when I use GraphicsRow or Grid the two graphs appear with different sizing:

GraphicsRow[{g1, g2}]

Grid[{g1, g2}]

I guess this is trivial but I cannot find a way so that the two graphs appear with the same size.

PS. Actually I want to replicate in Mathematica the following figure starting from scratch.

enter image description here

$\endgroup$
  • $\begingroup$ do you get what you need if you add the option AspectRatio -> 1 to g1 and g2? $\endgroup$ – kglr Dec 22 '18 at 1:23
  • $\begingroup$ @kglr No. The squate appears as a rectangle now. $\endgroup$ – Dimitris Dec 22 '18 at 1:29
  • $\begingroup$ @kglr I tried to clarify my question. See the edit. $\endgroup$ – Dimitris Dec 22 '18 at 1:34
1
$\begingroup$

Update:

ClearAll[arrowAxes, annotatedArrow]
arrowAxes[lbl_, lngth_: 1/2, asize_: Large, off_: {20, -15}] := 
  {Arrowheads[asize], Arrow[{{0, 0}, {0, lngth}}], Arrow[{{0, 0}, {lngth, 0}}], 
   Text[lbl[[1]], Offset[off, {0, lngth}]], 
   Text[lbl[[2]], Offset[Reverse[off], {lngth, 0}]]}

annotatedArrow[lbls_, fromto_: {{0, 0}, {0, 1}}, size_: .025] := 
 Module[{ends = Graphics[{AbsoluteThickness[1/5], 
      Line[{{-1, 1/2}, {0, 0}, {-1, -1/2}}], Line[{{0, 1}, {0, -1}}]}], 
   labels = Graphics[{Text[Framed[#, FrameStyle -> None, Background -> White], 
      {0, 0}, Center]}] & /@ lbls}, 
  {Arrowheads[{{-size, 0, ends},
      ## & @@ Thread[{size, Subdivide[1 + Length@lbls][[2 ;; -2]], labels}], 
    {size, 1, ends}}], Arrow[fromto]}]

Examples:

isa = {300, 300};
isb = ShearingTransform[30 Degree, {1, 0}, {0, 1}][isa];
pnt = ShearingTransform[30 Degree, {1, 0}, {0, 1}][{0, 1}];
ga = Graphics[{EdgeForm[{Thick, Blue}], FaceForm[], Rectangle[], 
    arrowAxes[Style[Subscript[e, #], 18, Bold] & /@ {1, 2}]}, 
   ImageSize -> isa, ImagePadding -> 25];
gb = Graphics[{{EdgeForm[{Dashed, Blue}], FaceForm[], Rectangle[]}, 
    GeometricTransformation[{EdgeForm[{Thick, Blue}], FaceForm[], 
      Rectangle[]}, ShearingMatrix[30 Degree, {1, 0}, {0, 1}]], 
    arrowAxes[Style[Subscript[e, #], 18, Bold] & /@ {1, 2}],
    Gray, AbsoluteThickness[1/5], 
    annotatedArrow[{Style[h, 18, Italic]}, Offset[{-20, 0}, #] & /@ {{0, 0}, {0, 1}}], 
    annotatedArrow[{Style[γ h, 18, Italic]}, Offset[{0, 20}, #] & /@ {{0, pnt[[2]]}, pnt}]},
   ImageSize -> isb, ImagePadding -> 25];

GraphicsRow[{ga, gb}, Spacings -> {0, 0}]

enter image description here

Grid[{{ga, gb}}]

enter image description here

Original answer:

Use ShearingTransform[30 Degree, {1, 0}, {0, 1}][{400, 400}] as the image size for g2 and add the option PlotRangePadding -> None to g1 and g2:

g1 = Graphics[{EdgeForm[{Thick, Blue}], FaceForm[], Rectangle[]}, 
   ImageSize -> {400, 400}, PlotRangePadding -> None];
g2 = Graphics[{{EdgeForm[{Dashed, Blue}], FaceForm[], Rectangle[]}, 
    GeometricTransformation[{EdgeForm[{Thick, Blue}], FaceForm[], 
      Rectangle[]}, ShearingMatrix[30 Degree, {1, 0}, {0, 1}]]}, 
   ImageSize -> ShearingTransform[30 Degree, {1, 0}, {0, 1}][{400, 400}], 
   PlotRangePadding -> None];

GraphicsRow[{g1, g2}, Spacings -> {0, 0}]

enter image description here

Grid[{{g1, g2}}]

enter image description here

$\endgroup$
  • $\begingroup$ Thanks. Not so trivial I think:-)! $\endgroup$ – Dimitris Dec 22 '18 at 1:47
  • $\begingroup$ @dimitris, you are welcome. Not trivial at all:) $\endgroup$ – kglr Dec 22 '18 at 1:56
  • $\begingroup$ Can you suggest me ways to include in the figures the annotated arrow, the unit vectors (arrows) and the texts or should I open a new thread? $\endgroup$ – Dimitris Dec 22 '18 at 2:07
  • $\begingroup$ @dimitris, thank you for the accept. I think unit vectors would not be difficult (I will post an update). I don't know an easy way to find the correct image size for g2 when texts are added. $\endgroup$ – kglr Dec 22 '18 at 13:57
  • $\begingroup$ Thanks again for your time! $\endgroup$ – Dimitris Dec 23 '18 at 0:58

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.