简体   繁体   中英

Does matplotlib change np.int to float automatically in x-axis?

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM