9
$\begingroup$

I have a contour plot that I'm trying to organize into a grid using Grid. But Grid changes the FrameTicksStyle font size of the fractions. How do I prevent this?

ContourPlot[x^2 + y^2, {x, 0, π}, {y, -π, π}, FrameTicks -> {{{-π/2, 0, π/2}, None}, {{}, None}}, FrameTicksStyle -> {Directive[14], Directive[14]}] Grid[{{%, %}, {%, %}}] 

gridded contour plots

If you're wondering why I'm using Grid instead of GraphicsGrid, it's just way easier for what I'm trying to accomplish.

$\endgroup$
3
  • 4
    $\begingroup$ But only on the fractions, as far as I can tell. Weird. $\endgroup$ Commented Oct 24, 2015 at 22:12
  • $\begingroup$ Does GraphicsGrid do the same thing? That allows you to set the size of the image, and the font sizes shouldn't change. Don't have access right now to test however. $\endgroup$ Commented Oct 25, 2015 at 3:28
  • $\begingroup$ GraphicsGrid retains the tick marks but adds extra space. $\endgroup$ Commented Oct 25, 2015 at 14:39

4 Answers 4

4
$\begingroup$

Here is something you might use as a work-around.

cp = ContourPlot[x^2 + y^2, {x, 0, π}, {y, -π, π}, FrameTicks -> {{{{-π/2, "-π/2"}, 0, {π/2, "π/2"}}, None}, {None, None}}, FrameTicksStyle -> {Directive[14], Directive[14]}]; Grid[{{cp, cp}, {cp, cp}}] 

grid

$\endgroup$
1
  • $\begingroup$ Interesting that this trick doesn't work if you try to use "proper" formatting on the fraction. Seems it's really aimed at not having tall tick numbers. This is definitely useful for my purposes, but I'm gonna leave the question open in case someone has a non-work-around answer. $\endgroup$ Commented Oct 25, 2015 at 5:12
4
$\begingroup$

Here is a proper workaround for your problem (which I consider as a nasty bug):

ContourPlot[x^2 + y^2, {x, 0, π}, {y, -π, π}, FrameTicks -> {{{-π/2, 0, π/2}, None}, {{}, None}}, FrameTicksStyle -> 14, BaseStyle -> {ScriptSizeMultipliers -> 1}] Grid[{{%, %}, {%, %}}] 

screenshot

Please report this bug to the tech support!

$\endgroup$
2
  • 1
    $\begingroup$ BaseStyle -> {ScriptSizeMultipliers -> 1} could also be used as an option just for Grid. $\endgroup$ Commented Oct 25, 2015 at 15:59
  • $\begingroup$ Super!! Completely unaware of ScriptSizeMultipliers. $\endgroup$ Commented Oct 26, 2015 at 1:42
1
$\begingroup$

Grid automatically changes the script level of its contents. This is what you're seeing. All you need to do is to add the option AllowScriptLevelChange->False to your Grid:

ContourPlot[ x^2 + y^2, {x, 0, π}, {y, -π, π}, FrameTicks -> {{{-π/2, 0, π/2}, None}, {{}, None}}, FrameTicksStyle -> {Directive[14], Directive[14]} ] Grid[ {{%, %}, {%, %}}, AllowScriptLevelChange->False ] 

enter image description here

enter image description here

$\endgroup$
0
$\begingroup$

This is an extendion of m_goldberg's answer.

Create the following fraction (Esc pi Esc ctrl-/2)

enter image description here

in your notebook and paste it into the text for the tick label. Then wrap the text in Style and make it size 18. When it shrinks in the grid you will approximately the same size for all of the tick labels.

cp = ContourPlot[x^2 + y^2, {x, 0, π}, {y, -π, π}, FrameTicks -> {{{{-π/2, Style["\!\(\*FractionBox[\(-π\), \(2\)]\)", 18]}, 0, {π/2, Style["\!\(\*FractionBox[\(π\), \(2\)]\)", 18]}}, None}, {None, None}}, FrameTicksStyle -> {Directive[14], Directive[14]}]; 

and then

Grid[{{cp, cp}, {cp, cp}}] 

Mathematica graphics

This is a fair amount of work. If you are doing this a great deal you will probably need to automate it.

$\endgroup$
2
  • $\begingroup$ You're gonna like this: ToString[-π/2, StandardForm] // InputForm $\endgroup$ Commented Oct 25, 2015 at 15:05
  • $\begingroup$ @JackLaVigne Your "solution" creates the opposite problem for cp (without Grid). Also it would be much simpler to write FrameTicks -> {{{{-\[Pi]/2, Style[-\[Pi]/2, 18]}, 0, {\[Pi]/2, Style[\[Pi]/2, 18]}}, None}, {None, None}} what produces the same result. $\endgroup$ Commented Oct 25, 2015 at 15:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.