0

Matplotlib generates a plot with unusual y-axis units when dealing with small numbers in a Numpy array.

Here is a minimal working example:

test = 1e6*array([.99999, .9999984, 1.000000013])
plot(test)

generates the following plot:

Matplotlib plot with irregular units

Is there a way to automatically prevent this behavior without directly inspecting the data? Thank you.

wil3
  • 2,877
  • 2
  • 18
  • 22
  • 1
    This looks like a bug. – Konrad Talik Mar 25 '15 at 22:21
  • 1
    First, I wouldn't call those small numbers. I would call them big numbers with small differences. Second, this is not a bug; it is a feature. Third, you ask for a 'way to automatically prevent this behavior', but don't specify what behavior you would prefer. Without clearer specifications of what you are looking for we (the SO community) can't be much help. Do you simply want a straight line to be plotted? If so, `gca().set_aspect('equal')` would do the trick. – farenorth Mar 25 '15 at 22:34
  • 3
    No, this is not a bug, it's the result of floating point math. – MattDMo Mar 25 '15 at 22:35
  • @farenorth Thank you for your friendly advice. I'm trying to plot something more complicated than a straight line, I just wanted to provide a minimum working example. I will edit my question to explicitly ask for the units to correctly be displayed in units of tick value/1e6, rather than the tick value plus a number. The problem persists if I remove the 1e6 out front, I just used that to demonstrate that this probably wasn't due to me hitting machine precision. – wil3 Mar 25 '15 at 23:29
  • also: http://stackoverflow.com/q/14711655/1461210, http://stackoverflow.com/q/27328895/1461210 – ali_m Mar 26 '15 at 01:50

0 Answers0