3

Let's say I have a code like shown below:

ListPlot[{{1,1},{2,1},{3,-1},{4,-1}}]

An output is shown on the figure.

Output

The "-" (minus) sign is shown near the negative tick values of the Y axis. Is there a straightforward way to make the "+" (plus) appear near the corresponding positive values, i.e. "+0.5" and "+1.0"?

Bulat
  • 323
  • 2
  • 9
  • 2
    does Ticks -> {Automatic, {#, NumberForm[#, {3, 1}, NumberPadding -> {"", "0"}, NumberSigns -> {"-", "+"}]} & /@ {-1.0, -0.5, 0.5, 1.}} give what you need? – kglr Oct 10 '17 at 15:23
  • .. or PaddedForm[#, {2, 1}, NumberSigns -> {"-", "+"}] instead of NumberForm[...? – kglr Oct 10 '17 at 15:39
  • Thanks for the answer! It helped – Bulat Oct 10 '17 at 18:20

1 Answers1

1
ClearAll[tF]
tF[divs_: {6, 6}] := Join @@ 
 {{#, PaddedForm[N@#, {3, 1}, NumberSigns -> {"-", "+"}], {0.02, 
           0}} & /@ #[[1]], 
  {#, ""} & /@ DeleteDuplicates@Flatten[#[[2]]]} & @ FindDivisions[{##}, divs] &;

ListPlot[{{1, 1}, {2, 1}, {3, -1}, {4, -1}}, Ticks -> {tF[{10, 6}], tF[]}]

enter image description here

kglr
  • 394,356
  • 18
  • 477
  • 896