首页 > 解决方案 > 更改 x 轴比例 im matplotlib imshow?

问题描述

代码给了我下面的图片。我需要在 x 轴上有更高的精度。现在我在每 100 个样本中有下一个点。但我希望更频繁地打印点(每 50 个样本)。

例如(x 轴): - 现在我有:0 100 200 ... - 我想要:0 50 100 150 200 ...

是否可以在此图像上使用网格制作此图像(在两个轴(x 和 y)的每个打印点上画线)?

Output:<br>

输出

Python 代码:'energy' 是 int32 类型的 numpy 二维数组(60,736)。

fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
plt.imshow(energy, aspect=10)
ax.axes.set_aspect(aspect=5)
plt.show()

标签: pythonmatplotlibimshow

解决方案


您可以通过以下方式设置轴定位器:

x = np.linspace(0,200,10)
y = x**2
fig, ax = plt.subplots()

ax.plot(x,y)

输出:

在此处输入图像描述

import matplotlib.ticker as plticker
fig, ax = plt.subplots()

ax.plot(x,y)

loc = plticker.MultipleLocator(base=50)
ax.xaxis.set_major_locator(loc)

输出:

在此处输入图像描述


推荐阅读