簡體   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