1
$\begingroup$

I have this code to get some density Plots, and the ticks on the x-axis has two decimals but at zero appears only one 0.. How can I make all ticks consistent such that it appears as 0.0 please? here is the code: first part I creat specific ticks form

<< MaTeX`
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}]; 
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];

and here is the density plot

fgt = Table[{x, y, Cos[10 x y]^2}, {x, -0.2, 0.2, 0.01}, {y, 0.0001, 
    5.0001, 0.1}];
With[{XZ = 100, YZ = 160, sx = 0.2, sy = 1, m = 1.3}, 
 ListDensityPlot[Flatten[fgt, 1], 
  RegionFunction -> Function[{x, y, f},  Abs[y + 1] - Abs[x] > 0 ], 
  InterpolationOrder -> 3, PlotRange -> {{-0.2, 0.2}, {0, 5}, All}, 
  ColorFunction -> (Blend[{RGBColor[0, 0, 0.7, 1], 
       RGBColor[0, 0.7, 1, 1], RGBColor[1, 1, 0, 0], 
       RGBColor[1, 0.5, 0, 1], RGBColor[0.6, 0, 0, 1]}, #] &), 
  ColorFunctionScaling -> False, 
  LabelStyle -> {FontFamily -> "Latin Modern Roman", Black, 
    FontSize -> 14}, 
  FrameLabel -> (MaTeX[#, Magnification -> m] &) /@ {"X", "Y"}, 
  Axes -> False, ImageSize -> Automatic -> {XZ, YZ}, 
  FrameTicks -> {{Tx[sy, 0.04, 0.02, 2 sy, YZ, XZ], 
     Tx[False, sy, 0.04, 0.02, 2 sy, YZ, XZ]}, {Tx[sx, 0.04, 0.02, 2 ,
       XZ, YZ], Tx[False, sx, 0.04, 0.02, 2 , XZ, YZ]}}, 
  PlotTheme -> {"mysty", 0.007, 0.007, YZ, XZ}, 
  PlotRangePadding -> None, PlotRangeClipping -> True]]    

enter image description here

$\endgroup$

1 Answer 1

2
+50
$\begingroup$

A way to go could be to use NumberForm, e.g. in you definition of s:

s[lbls_, j_, tl_] := Table[{j i, If[lbls, NumberForm[j i, {2, 1}], ""], {0, -tl}, Black}, {i, -10^2, 10^2}];

This changes in your code also thy y-axis ticks, but if you don't want that you can always use two different ticks functions.

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.