Skip to main content

plotting - Is there an option to change the space/distance between tick labels and axes labels for plots?


In an attempt to squeeze more plots and controls into the limited space for a demo UI, I am trying to remove any extra white spaces I see.


I am not sure what options to use to reduce the amount of space between the ticks labels and the actual text that represent the labels on the axes.


Here is a small Plot example using Frame->True (I put an outside Frame as well, just for illustration, it is not part of the problem here)


Framed[


Plot[Sin[x], {x, -Pi, Pi},
Frame -> True,
FrameLabel -> {{Sin[x], None}, {x,
Row[{"This is a plot of ", Sin[x]}]}},
ImagePadding -> {{55, 10}, {35, 20}},
ImageMargins -> 0,
FrameTicksStyle -> 10,
RotateLabel -> False
],


FrameMargins -> 0
]

Mathematica graphics


Is there an option or method to control this distance?


Notice that ImagePadding affects distance below the frame label, and not between the frame label and the ticks. Hence changing ImagePadding will not help here.


Depending on the plot and other things, this space can be more than it should be. The above is just a small example I made up. Here is a small part of a UI, and I think the space between the t(sec) and the ticks is too large. I'd like to reduce it by few pixels. I also might like to push the top label down closer to the plot by few pixels also.


Mathematica graphics


I am Using V9 on windows.


update 12/22/12



Using Labeld solution by @kguler below is a good solution, one just need to be little careful with the type-sitting for the labels. Plot automatically typeset things as Text in TraditionalFormat, which is a nice feature. To do the same when using Labeled one must do this manually using TraditionalForm and Text as well.


Here is example to show the difference


1) Labeled used just with TraditionalForm. The left one uses Plot and the right one uses Labeled with TraditionalForm. Notice the difference in how labels look.


Grid[{
{

Plot[Sin[x], {x, -Pi, Pi}, Frame -> True,
FrameLabel -> {{Sin[x], None}, {x, E Tan[x] Sin[x]}},
ImageSize -> 300, FrameTicksStyle -> 10, FrameStyle -> 16,RotateLabel -> False],


Labeled[
Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, ImageSize -> 300],
TraditionalForm /@ {Sin[x], x, E Tan[x] Sin[x]}, {Left, Bottom, Top},
Spacings -> {0, 0, 0}, LabelStyle -> "Panel"]
}

}, Frame -> All]

Mathematica graphics


2) Now we do the same, just need to add Text to get the same result as Plot.



Grid[{
{
Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, FrameTicksStyle -> 10,
FrameStyle -> 16,
FrameLabel -> {{Sin[x], None}, {x, E Tan[x] Sin[x]}},
ImageSize -> 300, RotateLabel -> False],

Labeled[
Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, ImageSize -> 300],
Text /@ TraditionalForm /@ {Sin[x], x, E Tan[x] Sin[x]}, {Left,

Bottom, Top}, Spacings -> {0, 0, 0}, LabelStyle -> "Panel"]
}

}, Frame -> All]

Mathematica graphics


Update 12/22/12 (2)


There is a big problem with controlling the spacing.


Labeled spacing only seem to work for horizontal and vertical spacing, taken togother.


i.e. One can't control spacing on each side of the plot separately? Here is an example, where I tried to move the bottom axes label up, this ended with moving the top label down as well. Which is not what I want.



Labeled[Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, ImageSize -> 300], 
Text /@ TraditionalForm /@ {Sin[x], x, E Tan[x] Sin[x]}, {Left,
Bottom, Top}, Spacings -> {-.2, -0.7}]

Mathematica graphics


Will see if there is a way to control each side spacing on its own. Trying Spacing->{-0.2,{-0.7,0}} does not work, it seems to take the zero in this case and ignored the -0.7


This gives the same result as above:


Labeled[Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, ImageSize -> 300], 
Text /@ TraditionalForm /@ {Sin[x], x, E Tan[x] Sin[x]}, {Left,
Bottom, Top}, Spacings -> {-.2, -0.7, .0}]


Mathematica graphics


ps. there might be a way to specify the spacing for each side with some tricky syntax. I have not figured it out yet. Still trying thing.... http://reference.wolfram.com/mathematica/ref/Spacings.html


update 12/22/12 (3) Using combination of ImagePadding and Spacing should have worked, but for some reason, the top label now is cut off. Please see screen shot. Using V9 on windows


enter image description here


Note: The above seems to be related to the issue reported here: some Graphics output do not fully render on the screen until an extra click is made into the notebook


Need an extra click inside the notebook. Then label become un-chopped !



Answer



The most convenient way I found is to wrap Plot (without FrameLabels and PlotLabel and with appropriate ImagePadding and ImageMargins) inside Labeled and use the Spacings option to position the labels:


 Labeled[Plot[Sin[x], {x, -Pi, Pi}, Frame -> True, 

ImagePadding -> {{20, 1}, {15, 2}}, ImageMargins -> 0,
FrameTicksStyle -> 10, RotateLabel -> False],
TraditionalForm /@ {Sin[x], x, Row[{"This is a plot of ", Sin[x]}]},
{Left, Bottom, Top},
Spacings -> {0, 0}, LabelStyle -> "Panel"]

enter image description here


Comments

Popular posts from this blog

front end - keyboard shortcut to invoke Insert new matrix

I frequently need to type in some matrices, and the menu command Insert > Table/Matrix > New... allows matrices with lines drawn between columns and rows, which is very helpful. I would like to make a keyboard shortcut for it, but cannot find the relevant frontend token command (4209405) for it. Since the FullForm[] and InputForm[] of matrices with lines drawn between rows and columns is the same as those without lines, it's hard to do this via 3rd party system-wide text expanders (e.g. autohotkey or atext on mac). How does one assign a keyboard shortcut for the menu item Insert > Table/Matrix > New... , preferably using only mathematica? Thanks! Answer In the MenuSetup.tr (for linux located in the $InstallationDirectory/SystemFiles/FrontEnd/TextResources/X/ directory), I changed the line MenuItem["&New...", "CreateGridBoxDialog"] to read MenuItem["&New...", "CreateGridBoxDialog", MenuKey["m", Modifiers-...

How to thread a list

I have data in format data = {{a1, a2}, {b1, b2}, {c1, c2}, {d1, d2}} Tableform: I want to thread it to : tdata = {{{a1, b1}, {a2, b2}}, {{a1, c1}, {a2, c2}}, {{a1, d1}, {a2, d2}}} Tableform: And I would like to do better then pseudofunction[n_] := Transpose[{data2[[1]], data2[[n]]}]; SetAttributes[pseudofunction, Listable]; Range[2, 4] // pseudofunction Here is my benchmark data, where data3 is normal sample of real data. data3 = Drop[ExcelWorkBook[[Column1 ;; Column4]], None, 1]; data2 = {a #, b #, c #, d #} & /@ Range[1, 10^5]; data = RandomReal[{0, 1}, {10^6, 4}]; Here is my benchmark code kptnw[list_] := Transpose[{Table[First@#, {Length@# - 1}], Rest@#}, {3, 1, 2}] &@list kptnw2[list_] := Transpose[{ConstantArray[First@#, Length@# - 1], Rest@#}, {3, 1, 2}] &@list OleksandrR[list_] := Flatten[Outer[List, List@First[list], Rest[list], 1], {{2}, {1, 4}}] paradox2[list_] := Partition[Riffle[list[[1]], #], 2] & /@ Drop[list, 1] RM[list_] := FoldList[Transpose[{First@li...

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...