0
$\begingroup$

Following code from frame tick label, with a slight modification in the FrameTicks->{{}{}}:

yticks = Charting`ScaledTicks[{Identity, Identity}, "TicksLength" -> {.03, .02}][##, {3, 10}] &;

xticks = Charting`ScaledTicks[{Identity, Identity}, "TicksLength" -> {.03, .02}][##, {6, 5}] &;

Plot[Sin[x], {x, -2.5, 2.5}, Frame -> True, Axes -> False, FrameTicks -> {{yticks, yticks}, {xticks, xticks}}]

The issue is that I get the same graph as obtained in the above link, but I also get the frame labels from -1 to 1 on the right y-axis and -2 to 2 on the upper x-axis. What I want is to get exactly the same tick markers as on the left y-axis and horizontal down x-axis, on right and top, but without numbers on them. In other words, how to get the same tick marks on all axis and only two axes numbered. Any suggestions on this, please?

Edited I am trying the above code with a log-log scale and it fails to work. Could it be checked, please? Thanks!

$\endgroup$
11
  • $\begingroup$ Maybe FrameTicks -> {{yticks, Automatic}, {xticks, Automatic}}? $\endgroup$
    – Hausdorff
    Jan 31, 2021 at 9:58
  • $\begingroup$ With the "Automatic" choice, the tick marks are not the same on the "right" and "left" and on the "top" and "bottom". $\endgroup$
    – SciJewel
    Jan 31, 2021 at 10:02
  • $\begingroup$ what version/OS are you using? $\endgroup$
    – kglr
    Jan 31, 2021 at 10:08
  • $\begingroup$ Mathematica 10 on Mac $\endgroup$
    – SciJewel
    Jan 31, 2021 at 10:12
  • 2
    $\begingroup$ As a workaround, perhaps you could define a copy of your ticks where you remove the labels with {a_?NumericQ, _, b___} :> {a, "", b} (c.f. the end of kglr's answer in the linked post ) So for example yticksBare = Charting`ScaledTicks[{Identity, Identity}, "TicksLength" -> {.03, .02}][##, {3, 10}] /. {a_?NumericQ, _, b___} :> {a, "", b}& $\endgroup$
    – Hausdorff
    Jan 31, 2021 at 10:16

2 Answers 2

1
$\begingroup$

Add the option FrameTicksStyle -> ({#, #} &@{Automatic, FontOpacity -> 0}) to make the top and right tick labels invisible:

Plot[Sin[x], {x, -2.5, 2.5}, 
 Frame -> True, Axes -> False, 
 FrameTicks -> {{yticks, yticks}, {xticks, xticks}}, 
 FrameTicksStyle -> ({#, #} &@{Automatic, FontOpacity -> 0})]

enter image description here

This works in Wolfram Cloud

$Version
"Version 12.3.0 for Linux x86 (64-bit) (May 10, 2021)" 

Also works in Version 11.3.0 for Microsoft Windows (64-bit) (March 7, 2018).

$\endgroup$
0
$\begingroup$

Try the following. Let us first define the ticks:

yLeft = Map[
   If[IntegerQ[#], {#, 
      Style[ToString[(#)], 12, Black, FontFamily -> "Times"]}, {# // 
       N, ""}] &, Range[-11/10, 11/10, 1/10]];
yRight = Range[-11/10, 11/10, 1/10] /. x_?NumberQ -> {N[x], ""};
xBottom = 
  Map[If[IntegerQ[#], {#, 
      Style[ToString[(#)], 12, Black, FontFamily -> "Times"]}, {# // 
       N, ""}] &, Range[-(13/5), 13/5, 1/5]];
xTop = Range[-(13/5), 13/5, 1/5] /. x_?NumberQ -> {N[x], ""};

Now we can plot:

Plot[Sin[x], {x, -2.5, 2.5}, Frame -> True, Axes -> False, 
 FrameTicks -> {{yLeft, yRight}, {xBottom, xTop}}]

with the following effect:

enter image description here

Have fun!

$\endgroup$
2
  • $\begingroup$ That's okay, but where is the log-log? $\endgroup$
    – SciJewel
    Feb 11, 2021 at 18:44
  • 2
    $\begingroup$ Your question contained no log-log plot $\endgroup$ Feb 12, 2021 at 11:30

Your Answer

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

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