October 19, 2024

import matplotlib.pyplot as plt
import numpy as np

# サンプルデータを生成
x = np.linspace(0, 10, 100)
y = np.sin(x)

# プロット
fig, ax = plt.subplots()
ax.plot(x, y)

# x軸の目盛りを整数のみに設定
ax.xaxis.set_major_locator(plt.MaxNLocator(integer=True))

ax.set_xaxis(0, 100)

# グラフを表示
plt.show()