1
$\begingroup$

I wrote this small code to get custom FrameTicks

TX[XZ_, YZ_] := Piecewise[{{XZ/YZ, XZ >= YZ}, {1, XZ < YZ}}]
s[j_, tl_] := Table[{j i, j i, {0, -tl}, Black}, {i, -10^2, 10^2}]; 
p[j_, ts_, ns_] := 
 Table[{(j (i))/ns, "", {0, -ts}, Black}, {i, -10^2, 10^2}];(*ns>1*)
ticks[j_, tl_, ts_, ns_] := ArrayFlatten[{{s[j, tl]}, {p[j, ts, ns]}}];
Tx[MSx_, Msz_, Ssz_, nSS_, XZ_, YZ_] := 
  ticks[MSx, Msz TX[XZ, YZ] , Ssz TX[XZ, YZ] , nSS];
System`PlotThemeDump`resolvePlotTheme[{"mysty", x_Real, y_Real, YZ_, 
   XZ_}, _] :=
  {AspectRatio -> 1, 
  LabelStyle -> {FontSize -> 18, Black, 
    FontFamily -> "Times New Roman"},
    FrameStyle -> Directive[{Black, Thickness[TX[YZ, XZ] x]}], 
    Frame -> True, 
    FrameTicksStyle -> {{Directive[Black, Thickness[TX[YZ, XZ] y]],  
     Automatic}, 
       {Directive[Black, Thickness[TX[YZ, XZ] y]], Automatic}}}    

Now I am using FrameTicks which works fine with Plot

With[{XZ = 400, YZ = 200, sx = 3, sy = 1}, 
  Plot[Sin[z], {z, -2 Pi, 2 Pi}, FrameLabel -> {"X", "Y"}, 
    Axes -> False, PlotStyle -> Directive[Red], 
    ImageSize -> Automatic -> {XZ, YZ}, 
    FrameTicks -> {{Tx[sy, 0.03, 0.015, 5 sy, YZ, XZ], Automatic},
        {Tx[sx, 0.03, 0.015, 2 sx, XZ, YZ], Automatic}}, 
    PlotTheme -> {"mysty", 0.003, 0.003, YZ, XZ}, ImagePadding -> 80]]   

enter image description here

Then, if I use ListLinePlot it is not working where the size of the Ticks on the Top and Right sides of the Frame is smaller

data = Table[{z, Sin[z]}, {z, -2 Pi, 2 Pi, 0.1}];
With[{XZ = 400, YZ = 200, sx = 3, sy = 1}, 
 ListLinePlot[data, FrameLabel -> {"X", "Y"}, Axes -> False, 
  PlotStyle -> Directive[Red], ImageSize -> Automatic -> {XZ, YZ}, 
  FrameTicks -> {{Tx[sy, 0.03, 0.015, 5 sy, YZ, XZ], 
     Automatic}, {Tx[sx, 0.03, 0.015, 2 sx, XZ, YZ], Automatic}}, 
  PlotTheme -> {"mysty", 0.003, 0.003, YZ, XZ}, ImagePadding -> 80]]

enter image description here

$\endgroup$
4
  • $\begingroup$ I see very faint green ticks. What kind of ticks are intended? $\endgroup$
    – SHuisman
    Commented Aug 10, 2020 at 17:03
  • $\begingroup$ @SHuisman, the problem is with the size of the ticks not the color, I update the question and code. $\endgroup$
    – MMA13
    Commented Aug 10, 2020 at 17:28
  • $\begingroup$ Looks like Plot replaces the Automatic ticks with a version of your custom ticks with the labels removed, while ListPlot simply leaves the Automatic there, resulting the different ticks. You should be able to simply add a way to your Tx to generate the ticks without labels, and use that to manually generate the other frame sides. $\endgroup$
    – Lukas Lang
    Commented Aug 11, 2020 at 14:14
  • $\begingroup$ @LukasLang, well at the beginning I did that and the Ticks were Ok but could not get rid of the Labels on the Top and Right sides of the Frame. So, I used Automatic to get the size fixed and get red of the labels (kindly, see this. Now If I impose the size of the Ticks with ListLinePlot I will get the problem back with the Labels again. $\endgroup$
    – MMA13
    Commented Aug 11, 2020 at 15:00

1 Answer 1

2
$\begingroup$

A solution based on what I suggested in the comments:

TX[XZ_, YZ_] := Piecewise[{{XZ/YZ, XZ >= YZ}, {1, XZ < YZ}}]
s[lbls_, j_, tl_] := Table[{j i, If[lbls, j i, ""], {0, -tl}, Black}, {i, -10^2, 10^2}];
p[j_, ts_, ns_] := Table[{(j (i))/ns, "", {0, -ts}, Black}, {i, -10^2, 10^2}];(*ns>1*)ticks[lbls_, j_, tl_, ts_, ns_] := ArrayFlatten[{{s[lbls, j, tl]}, {p[j, ts, ns]}}];
Tx[lbls_ : True, MSx_, Msz_, Ssz_, nSS_, XZ_, YZ_] := ticks[lbls, MSx, Msz TX[XZ, YZ], Ssz TX[XZ, YZ], nSS];

System`PlotThemeDump`resolvePlotTheme[{"mysty", x_Real, y_Real, YZ_, XZ_}, _] := {AspectRatio -> 1, LabelStyle -> {FontSize -> 18, Black, FontFamily -> "Times New Roman"}, FrameStyle -> Directive[{Black, Thickness[TX[YZ, XZ] x]}], Frame -> True, FrameTicksStyle -> {{Directive[Black, Thickness[TX[YZ, XZ] y]], Automatic}, {Directive[Black, Thickness[TX[YZ, XZ] y]], Automatic}}}

data = Table[{z, Sin[z]}, {z, -2 Pi, 2 Pi, 0.1}];
With[{XZ = 400, YZ = 200, sx = 3, sy = 1},
 ListLinePlot[
  data,
  FrameLabel -> {"X", "Y"},
  Axes -> False,
  PlotStyle -> Directive[Red],
  ImageSize -> Automatic -> {XZ, YZ},
  FrameTicks -> {
    {
     Tx[sy, 0.03, 0.015, 5 sy, YZ, XZ],
     Tx[False, sy, 0.03, 0.015, 5 sy, YZ, XZ]
     }, {
     Tx[sx, 0.03, 0.015, 2 sx, XZ, YZ],
     Tx[False, sx, 0.03, 0.015, 2 sx, XZ, YZ]
     }
    },
  PlotTheme -> {"mysty", 0.003, 0.003, YZ, XZ},
  ImagePadding -> 80
  ]
 ]

enter image description here

This works by adding an optional lbls parameter to the tick function that can be used to omit the labels from the generated ticks. This parameter is then simply set to False for the appropriate axes, leading to properly sized ticks.

$\endgroup$
1
  • $\begingroup$ I see how you do it, thanks to a lot! $\endgroup$
    – MMA13
    Commented Aug 12, 2020 at 11:46

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.