6
$\begingroup$

I have the following code:

    h[k_, x_, t_] = 
  Boole[x < t < x + k] Boole[x + k <= 1] + 
   Boole[x < t < 1 || 0 < t < x + k - 1] Boole[x + k > 1];

pl[k_, t_, ep_] := 
 Plot[h[k, x, t], {x, 0, 1}, 
  PlotRange -> {{-ep, 1 + 0.4 ep}, {-ep, 1 + .4 ep}}, 
  PlotStyle -> Thick, Ticks -> {{0, t, t - k, 1 + t - k, 1}, {0, 1}}]

If I now say

GraphicsGrid[{{pl[.4, .3, 0], pl[.4, .8, 0]}}]

then I get

enter image description here

with only part of the ticks along the horizontal axis showing.

If I say

GraphicsGrid[{{pl[.4, .3, .1], pl[.4, .8, .1]}}]

then I get

enter image description here

with the ticks at the origin not showing.

How can I fix these flaws?


It has been suggested that I use Frame and FrameTicks. However, I do not want frames. Also, this does not work either:

ep = 0;
h[k_, x_, t_] = 
  Boole[x < t < x + k] Boole[x + k <= 1] + 
   Boole[x < t < 1 || 0 < t < x + k - 1] Boole[x + k > 1];

pl[k_, t_, ep_] := 
 Plot[h[k, x, t], {x, 0, 1}, 
  PlotRange -> {{-ep, 1 + 0.4 ep}, {-ep, 1 + .4 ep}}, 
  PlotStyle -> Thick,
  Frame -> True, FrameTicks -> {{0, t, t - k, 1 + t - k, 1}, {0, 1}}]

GraphicsGrid[{{pl[.4, .3, 0], pl[.4, .8, 0]}}]

enter image description here

Some of the ticks are showing only partially.

I am wondering why GraphicsGrid cannot handle such simple tasks.


It has also been suggested that there may be a problem with my global plot options. I do not think I have ever enabled any global plot options. Here are some possibly relevant Graphics Options for Global Preferences:

enter image description here

enter image description here

$\endgroup$
6
  • 1
    $\begingroup$ I'd suggest you use Frame and FrameTicks instead. These should be proplerly handled by GraphicsGrid $\endgroup$
    – Lukas Lang
    Aug 14, 2022 at 17:04
  • 1
    $\begingroup$ You can selectively hide edges of the frame to get them only on the left and bottom sides (something like Frame->{{True,False},{True,False}}. As for the clipping that is still present: what version are you using? $\endgroup$
    – Lukas Lang
    Aug 14, 2022 at 17:50
  • $\begingroup$ @LukasLang : I am using Version 13.1.0 for Microsoft Windows (64-bit) (June 16, 2022). $\endgroup$ Aug 14, 2022 at 17:52
  • $\begingroup$ On my machine (Win64+M13.1), your commands lead to plots with full tick labels. Do you have some kind of global plot options enabled? $\endgroup$
    – Oscillon
    Aug 14, 2022 at 18:20
  • $\begingroup$ @Oscillon : Thank you for your comment. I do not think I have ever enable any global plot options. I do not even know how to do that. Could you please tell me how to check that? $\endgroup$ Aug 14, 2022 at 18:32

1 Answer 1

7
$\begingroup$

I have found out that this behavior was caused by me changing the magnification globally. I changed it because the default font size for Mathematica 13.1 is too large.

Anyhow, this should not have caused the clipping of the ticks. So, this appears to be a Mathematica bug, and I have reported it to the Wolfram support as such.


Update: I have now received a response from Wolfram that this is indeed a known issue, to be resolved in a future version of Mathematica.

For now, using ImagePadding is suggested, which indeed helps, even with global magnification set at 0.8: The code

ClearAll["Global`*"]

h[k_, x_, t_] = 
  Boole[x < t < x + k] Boole[x + k <= 1] + 
   Boole[x < t < 1 || 0 < t < x + k - 1] Boole[x + k > 1];

pl[k_, t_, ep_] := 
 Plot[h[k, x, t], {x, 0, 1}, 
  PlotRange -> {{-ep, 1 + 0.4 ep}, {0, 1 + .4 ep}}, 
  PlotStyle -> Thick, 
  Ticks -> {{0, t, 0.3 - 0.4, t - k, 1 + t - k, 1}, {0, 1}}, 
  ImagePadding -> 20]

GraphicsGrid[{{pl[.4, .3, 0], pl[.4, .8, 0]}}]

produces a desired image:

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.