I wonder why matplotlib changes the np.int to float in drawing especially in x-axis. Is that normal behavior of matplotlib or there might be something wrong in my jupyter status?
import numpy as np
import matplotlib.pyplot as plt
ys = np.arange(4)
print(ys)
fig, ax = plt.subplots(1,1, figsize=(16,5))
xs = np.arange(1,5,dtype=np.int)
print(xs)
ax.plot(xs, ys, marker='o')
ax.set_xlabel("dtype = int", fontsize=15)
ax.set_ylabel("y-values", fontsize=15)
plt.show()
It's just the tick locator, you can set it to integers only. See here for details:
import matplotlib as mpl
ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.