0

I've been trying to make a scatterplot with maptlotlib where the axes are integers, and I had attempted to use MultipleLocator to do so (I had previously attempted to use MaxNLocator(integer=True), as found in this thread, to no avail.)

training_data_figure = plt.figure()
training_data_plot = training_data_figure.add_subplot(1, 1, 1)

training_data_plot.scatter(training_x_points, training_y_points)
training_data_plot.get_yaxis().set_major_locator(matplotlib.ticker.MultipleLocator(10))
# ...

plt.plot()

Hoewver, this oddly produces non-integer ticks.

Graph output, with y-axis having non-integer ticks

The docs state that MultipleLocator will "Set a tick on each integer multiple of a base within the view interval," which is clearly not what's happening here.

These points on the ticks seem to be actual points from my data, oddly enough.

How can I force these ticks to be integers?

ollien
  • 4,418
  • 9
  • 35
  • 58
  • At first sight, you are using strings instead of numbers for your y-axis. Maybe try `training_y_points = [float(y) for y in training_y_points]` or something similar. – JohanC Apr 11 '20 at 19:23
  • I _JUST_ found this when working on another pat of my assignment. This is exactly what it was. Thank you. – ollien Apr 11 '20 at 19:24

0 Answers0