Antys
Antys

Reputation: 49

Matplotlib showing wrong y-axis values

My code is very simple:

values = [-2071238, -2071241, -2071240, -2071242, -2071244, -2071239, -2071221, -2071194, -2071224, -2071240, -2071244, -2071241, -2071240, -2071241, -2071237, -2071223, -2071205, -2071225, -2071238]
indx = [0.0, 20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 320.0, 340.0, 360.0]

plt.scatter(indx, values)

#rendering
plt.xlabel("Axis 1")
plt.ylabel("Axis 2")
title = "All"
plt.title(title)
plt.savefig(title + ".png")
plt.show()

However, the resulting figure is the following:

picture

Which obviously doesn't have the good y values for each points.

Am I doing something wrong or forgetting something?

Upvotes: 3

Views: 6867

Answers (1)

Michał Machnicki
Michał Machnicki

Reputation: 2887

Your figure does have good values on the y axis, but they have an offset. The offset can be disabled:

import matplotlib.pyplot as plt

values = [-2071238, -2071241, -2071240, -2071242, -2071244, -2071239, -2071221, -2071194, -2071224, -2071240, -2071244, -2071241, -2071240, -2071241, -2071237, -2071223, -2071205, -2071225, -2071238]
indx = [0.0, 20.0, 40.0, 60.0, 80.0, 100.0, 120.0, 140.0, 160.0, 180.0, 200.0, 220.0, 240.0, 260.0, 280.0, 300.0, 320.0, 340.0, 360.0]

plt.scatter(indx, values)

# disabling the offset on y axis
ax = plt.gca()
ax.ticklabel_format(useOffset=False)

#rendering
plt.xlabel("Axis 1")
plt.ylabel("Axis 2")
title = "All"
plt.title(title)
plt.savefig(title + ".png")

plt.show()

enter image description here

Upvotes: 5

Related Questions