# Is it possible to ask Mathematica to draw a plot like the given one?

Is it possible to ask Mathematica to draw a plot like this?

• Have a look at Graphics. You can certainly draw the plot you show. I suggest you have a go and come back with an edit showing your difficulties.
– Hugh
Jan 3, 2021 at 21:42
• @Hugh Thank you, I will try it.
– user76607
Jan 3, 2021 at 22:08
• I would use lines. Line[{{x1,y1},{x2,y2},{x3,y3},{x4,y4},{x1,y1}] where the {xn,yn} are the coordinates. That will give you a four sided polygon. As you want different line thickness perhaps it would be better to use ... Thickness[0.1], Line[{{x1,y1},{x2,y2}}]... where Thickness is a graphics directives. As you want dashing then you will need Dashing as well.
– Hugh
Jan 3, 2021 at 22:40

Graphics[{

(* The diamonds, built as rotated and translated Rectangle objects *)
{
FaceForm[None], EdgeForm[Black],
Translate[Rotate[Rectangle[{-1, -1}, {1, 1}], 45 Degree], {-2, 0}],
Translate[Rotate[Rectangle[{-1, -1}, {1, 1}], 45 Degree], {2, 0}]
},

(* The dashed rectangle *)
{
FaceForm[None], EdgeForm[Dashed],
Rectangle[{-2, -7/4}, {2, 7/4}]
},

(* The thick horizontal line *)
{Thickness[0.01], Line[{{-Pi/2, -1}, {Pi/2, -1}}]},

(* The thick inner sides of the diamonds *)
{Thickness[0.01],
Line[{{-2, Sqrt[2]}, {-2 + Sqrt[2], 0}, {-2, -Sqrt[2]}}],
Line[{{2, Sqrt[2]}, {2 - Sqrt[2], 0}, {2, -Sqrt[2]}}]
},

(* The text labels *)
{
Inset[Style["x", FontSize -> Scaled[0.05], FontFamily -> "Times"], {-1.1, 1}],
Inset[Style["y", FontSize -> Scaled[0.05], FontFamily -> "Times"], {-1.1, -0.75}]
}
}
]


This is exactly the kind of exercise the tickles my OCD tendencies, so I enjoyed building it by hand, but it would be far quicker (and probably overall more sensible) to build this in a vector graphics software :-) .

• Thank you very much. Can we do something with the endpoints of the thick lines which pass the dashed line? And is it possible to have edge labels in latex format?
– user76607
Jan 3, 2021 at 23:52
• I gave a +1 because of the last sentence. Jan 4, 2021 at 4:36

We can resize the dashed rectangle interactively using LocatorPane and use custom arrowheads to add the labels:

{ahx, ahy} = Graphics @ Text[Style[#, 16], {0, 0}, {0, # /. {"x" -> -3/2, "y" -> 1}}]&/@
{"x", "y"};


Unit square with two thick edges and labels:

diamondlines = {Line[{{0, 0}, {0, 1}, {1, 1}}], Thick,
Arrowheads[{{.05, .75, {ahy, 1}}}], Arrow[{{0, 0}, {1, 0}}],
Arrowheads[{{.05, .5, {ahx, 1}}}], Arrow[{{1, 1}, {1, 0}}]};



locatorshape = Graphics[{Opacity[0], Point[{1, 1}/2], Opacity[1, Red],
Polygon[{{-1, 0}, {0, 0}, {0, -1}}]}, ImageSize -> 30];


We rotate and translate diamondlines to get the two diamonds and combine them with the dashed rectangle and the thick horizontal line:

DynamicModule[{pt = {{2.2, 2}}},
LocatorPane[Dynamic[pt],
Dynamic @ Framed @ Graphics[{
{#, Translate[Rotate[# /. Arrow -> Line, Pi, {0, pt[[1, 2]]/2}],
{pt[[1, 1]], 0}]}& @ Translate[Rotate[diamondlines, Pi/4, {0, 0}],
{0, (pt[[1, 2]] - Sqrt[2])/2}],
Thick, Line[{{Sqrt[2]/4, (2 pt[[1, 2]] - Sqrt[2])/4},
{pt[[1, 1]] - Sqrt[2]/4, (2 pt[[1, 2]] - Sqrt[2])/4}}],
EdgeForm[Dashed], FaceForm[], Rectangle[{0, 0}, pt[[1]]]},
PlotRange -> {{-1, pt[[1, 1]] + 1}, {-1, pt[[1, 2]] + 1}},
ImageSize -> 500],
Appearance -> locatorshape]]