6
$\begingroup$

I have the following 4 plots sharing a common X and Y axes. I place 4 plots in a grid of 2 by 2. I do not want to use separate X and Y-axis labels for each of them. Instead, I want to put a single X-axis and Y-axis for 4 plots in a single frame.

 GraphicsGrid[{ { Plot[ {x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}] ], Plot[ {x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}] ]}, { Plot[ {x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}] ], Plot[ {x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}] ]} }, FrameLabel -> {"x-axis", "y-axis"}] 

I tried to use ResourceFunction["PlotGrid"] to place X-axis and Y-axis, but I could not do it.

Any help?

enter image description here

Here is the example to show the format of the axis labels.

enter image description here

$\endgroup$
2
  • $\begingroup$ Could you please draw by hand how the single-X and single-Y axes will appear on the final plot? $\endgroup$ Commented Feb 4, 2024 at 15:34
  • $\begingroup$ @Syed: I will do it in a moment. $\endgroup$ Commented Feb 4, 2024 at 15:55

3 Answers 3

8
$\begingroup$

I don't have any difficulties with PlotGrid:

ops = Sequence[ Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}] ]; ResourceFunction["PlotGrid"][{{ Plot[{x, x^3}, {x, 0, 1}, Evaluate @ ops], Plot[{x, x^3}, {x, 0, 1}, Evaluate @ ops]}, {Plot[{x, x^3}, {x, 0, 1}, Evaluate @ ops], Plot[{x, x^3}, {x, 0, 1}, Evaluate @ ops]}}, Spacings -> 10, "ShowFrameLabels" -> Automatic, FrameLabel -> {"x-axis", "y-axis"}] 

enter image description here

$\endgroup$
5
  • $\begingroup$ Individual plots should be separated with some space and Y-axis and X-axis be placed for the frame of the 4 plots. $\endgroup$ Commented Feb 4, 2024 at 15:57
  • $\begingroup$ Please see update (PlotGrid has many options) $\endgroup$ Commented Feb 4, 2024 at 16:08
  • $\begingroup$ I am sorry that I could not explain it better. The update is good but still I like to place X-axis label X-axis on the horizontal axis and Y-axis label as Y-axis on the vertical axis. $\endgroup$ Commented Feb 4, 2024 at 16:12
  • $\begingroup$ Maybe like the latest revision? $\endgroup$ Commented Feb 4, 2024 at 16:17
  • $\begingroup$ YES. This is the format. $\endgroup$ Commented Feb 4, 2024 at 16:19
4
$\begingroup$
Grid[{{Rotate[Text[Style["Y-Axis", 18]], 90*Degree], Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]], Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]]}, {SpanFromAbove, Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]], Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]]}, {, Text[Style["X-Axis", 18]], SpanFromLeft}}, Alignment -> {Center, Center, {Center, Center}},, Spacings -> {1, 1}] 

enter image description here

$\endgroup$
4
$\begingroup$
 gg = GraphicsGrid[{ {Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]], Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]]}, {Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]], Plot[{x, x^3}, {x, 0, 1}, Frame -> True, PlotLegends -> Placed["Expressions", {Left, Top}]]}}]; Labeled[#, {"y-axis", "x-axis"}, {Left, Bottom}, RotateLabel -> True] & @ gg 

enter image description here

Add the option ImageMargins -> 10 to GraphicsGrid[...] to get

enter image description here

Update: To add a legend and a plot label:

legend = LineLegend[97, { "I", "S", "R"}, LegendLayout -> "Row"]; Legended[#, Placed[legend, Below]] & @ Labeled[# , {"Title for the group", "y-axis", "x-axis"}, {Top, Left, Bottom}, RotateLabel -> True] & @ gg 

enter image description here

$\endgroup$
2
  • $\begingroup$ Treating this group of 4 plots as a single plot, how can I place a single PlotLabel->"Title for the group" at the top and a single PlotLegends->{"I","S","R"} at the bottom below X-axis. Sorry for this extra question which is not in the original question. $\endgroup$ Commented Feb 5, 2024 at 16:43
  • 1
    $\begingroup$ @TugrulTemel, please see the update. $\endgroup$ Commented Feb 5, 2024 at 19:28

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.