Home > Enterprise >  matplot lib showing strange offset at top
matplot lib showing strange offset at top

Time:02-15

Matplotlib is behaving strangely on some very large values.

I want the graph to show the ACTUAL numbers, in my case 61577 and 61578.

Instead its showing only the 1s place, and doing a 6.15700000e4 at the very top. Is there an option i need to specify to get the graph to show actuals instead of an offset?

There is definitely some kind of scale being applied; when I change the numbers to 1577 and 1578, it looks like you'd expect it to. So what do I need to turn off?

Simple test case:

import matplotlib.pyplot as plt
y = [61577,61577,61577,61577,61577,61577,61578,61577,61578,61578,61578,61578,61578,61578,61578,61578,61578,61578,61578]
x = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]

plt.plot(x, y)

plt.xlabel('x - axis')
plt.ylabel('y - axis')

plt.show()

Strange offset on graph

CodePudding user response:

This is because the y axis numbers are so big, it changes the range of the graph. 6.15700000e4 is just standard notation for 6,157. It is displaying the first 4 numbers of your data on the y axis "6157" and then the final digit so the graph is easier to see. That is also why the spike looks so large, but in reality it is just a change in 1. Here's one way to change the axis range so it doesn't use scientific notation

import matplotlib.pyplot as plt
y = [61577,61577,61577,61577,61577,61577,61578,61577,61578,61578,61578,61578,61578,61578,61578,61578,61578,61578,61578]
x = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18]

_, ax = plt.subplots()
ax.plot(x, y)
ax.ticklabel_format(useOffset=False)
plt.xlabel('x - axis')
plt.ylabel('y - axis')
plt.show()
  • Related