Custom Control of Axes and Plot Labels in 2D and 3D Plots
- To: mathgroup at smc.vnet.net
- Subject: [mg82144] Custom Control of Axes and Plot Labels in 2D and 3D Plots
- From: "David Park" <djmpark at comcast.net>
- Date: Sat, 13 Oct 2007 03:51:23 -0400 (EDT)
There have been a number of questions concerning the control and placement of axis labels and overall plot labels in graphics. I believe that for 2D graphics there is a complete solution. For 3D graphics it is possible to control the placement of the labels but if the image is rotated it will always be possible to obtain overlaps between axis labels and tick marks. Nevertheless it should be possible to place axis labels for a satisfactory result within range of a recommend viewpoint. For 2D plots, by using PlotRange, PlotRangePadding, ImagePadding and Text statements with Scaled coordinates we can place the various plot labels where we wish. The following is an example where the plot labels and axis labels have been specifically placed: Graphics[ {Circle[], Text["x", Scaled[{0.55, -0.06}]], Text["y", Scaled[{-0.08, 0.55}]], Text[Style["A Custom Plot", Large], Scaled[{0.5, 1.1}]], Text["Placing Our Own Labels", Scaled[{0, 1.02}], {-1, 0}]}, PlotRange -> {{-1, 1}, {-1, 1}}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {35, 60}}, Frame -> True] For a 3D plot the problem is more difficult because of the possibility of rotating the image. We can place the plot label using Epilog. For short axes labels we can place them just inside the bounding box using Text statements. Inside the box they tend to be disentangled from the tick labels. But it is always possible to select a viewpoint that can cause overlap. The only recourse is to place the axes labels according to the predominate view that is wanted. We should probably also set the AxesEdge option to always keep the axes with the labels. The SphericalRegion and RotationAction options provide a 'jump free' interaction with the mouse. Graphics3D[ {Sphere[], Text["x", Scaled[{0.5, 0.04, 0.04}]], Text["y", Scaled[{0.96, 0.5, 0.04}]], Text["z", Scaled[{0.04, 0.04, 0.5}]]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style["A Custom Plot", Large], Scaled[{0.5, 1.2}]], Text["Placing Our Own Labels", Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> "Clip"] With longer axes labels the problem again becomes more difficult because there is more chance for overlap of the labels and ticks. The following is an attempted solution that works within a selected range of viewpoints. Graphics3D[ {Sphere[], Text["x axis", Scaled[{0.5, 0.04, 0.04}], {-1, 0}], Text["y axis", Scaled[{1.1, 0.5, -0.10}], {-1, 0}], Text["z axis", Scaled[{-0.10, -0.10, 0.5}], {0, 0}, {0, 1}]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style["A Custom Plot", Large], Scaled[{0.5, 1.2}]], Text["Placing Our Own Labels", Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> "Clip"] If we can settle for a fixed viewpoint it is even possible to have the labels parallel to the axes. (However, I don't think that angled text always looks that great on the screen. It may look better printed.) axisstyle[s_] := Style[s, FontSize -> 14, FontWeight -> "Bold"]; Graphics3D[ {Sphere[], Text[axisstyle["x axis"], Scaled[{0.5, 0.04, 0.04}], {0, 0}, {1, -0.4}], Text[axisstyle["y axis"], Scaled[{1.1, 0.5, -0.10}], {-1, 0}, {1, 1.7}], Text[axisstyle["z axis"], Scaled[{-0.10, -0.10, 0.5}], {0, 0}, {-0.15, 1}]}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}, Epilog -> {Text[Style["A Custom Plot", Large], Scaled[{0.5, 1.2}]], Text["Placing Our Own Labels", Scaled[{0, 1.13}], {-1, 0}]}, PlotRangePadding -> 0.05, ImagePadding -> {{35, 20}, {30, 80}}, Axes -> True, AxesEdge -> {{-1, -1}, {1, -1}, {-1, -1}}, SphericalRegion -> True, RotationAction -> "Clip"] -- David Park djmpark at comcast.net http://home.comcast.net/~djmpark/