0

I'm trying to specify yaxis tick labels from 0 to 1.0 in steps of 0.1. This is what I get:

ygrids=Range[0,1.0,0.1];
0.,0.1,0.2,0.30000000000000004,0.4,0.5,0.6000000000000001,0.7000000000000001,0.8,0.9,1.}

Round[ygrids,0.01] doesn't fix it. (0.001 fixes all but the 7.0000x)

This is too simple to be this hard!

Help appreciated (version 10.1)

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
Tom Mozdzen
  • 521
  • 5
  • 16
  • Round[ygrids, 1/10] // N, Range[0, 1, 1/10] // N,N@Rationalize@Range[0, 1.0, 0.1]... – ciao Aug 12 '15 at 00:56
  • You can format inline code and code blocks by selecting the code and clicking the {} button above the edit window. The edit window help button ? is also useful for learning how to format your questions and answers. You may also find this this meta Q&A helpful – Michael E2 Aug 12 '15 at 01:02
  • This needs to be marked as a duplicate, not closed as a "simple mistake." – Mr.Wizard Aug 12 '15 at 02:08
  • 1
  • @Mr.Wizard: a duplicate of a simple mistake? ;-) – ciao Aug 12 '15 at 02:31
  • @ciao It's an issue that comes up again and again, and seems to not be so simple. It's also been addressed before, and if it was a valid question then it probably should be now, too. And counting duplicates is the method currently in use (my proposal) for applying the faq tag, so this helps site organization as well. – Mr.Wizard Aug 12 '15 at 04:00
  • I looked at most of those posts and the answers did not "feel good". My solution based upon the related posts was to do this: ygrids=Range[0,1.0,0.1'2] which seems like a ridiculous thing to have to do. I haven't tried the solution offered below yet as I'm adding a frame and grids, and I'd hope that they would all play nicely. – Tom Mozdzen Aug 12 '15 at 16:26

1 Answers1

1

I think you should cut the Gordian Knot and forget about rounding.

Plot[x, {x, 0, 1}, Ticks -> {Automatic, Range[0., 1., .1]}]

plot

The lack of rounding has no visible affect on the plot.

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
  • Yes, I will give this a try next time as I like the simplicity. I hope it works on more complicated graph axis ticks as well. – Tom Mozdzen Aug 12 '15 at 16:27