繁体   English   中英

matplotlib 是否将 np.int 更改为在 x 轴上自动浮动?

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

我想知道为什么 matplotlib 将 np.int 更改为在绘图中浮动,尤其是在 x 轴上。 这是 matplotlib 的正常行为还是我的 jupyter 状态可能有问题?

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()

在此处输入图像描述

它只是刻度定位器,您只能将其设置为整数。 有关详细信息,请参见 此处

import matplotlib as mpl
ax.xaxis.set_major_locator(mpl.ticker.MaxNLocator(integer=True))

在此处输入图像描述

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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