在 matplotlib imshow 中更改 x 轴刻度?
change x axis scale im matplotlib imshow?
代码为我提供了下图。我需要在 x 轴上有更高的精度。现在我每 100 个样本都有下一个点。但我希望更频繁地打印点(每 50 个样本)。
例如(x轴):
- 现在我有:0 100 200 ...
- 我想要:0 50 100 150 200 ...
是否可以将此图像制作成网格向上(在双轴(x 和 y)的每个打印点上画线)?
Output:<br>
Python code:
'energy' is numpy 2D array(60,736) of int32 type.
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
plt.imshow(energy, aspect=10)
ax.axes.set_aspect(aspect=5)
plt.show()
您可以通过以下方式设置轴定位器:
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)
输出:
代码为我提供了下图。我需要在 x 轴上有更高的精度。现在我每 100 个样本都有下一个点。但我希望更频繁地打印点(每 50 个样本)。
例如(x轴): - 现在我有:0 100 200 ... - 我想要:0 50 100 150 200 ...
是否可以将此图像制作成网格向上(在双轴(x 和 y)的每个打印点上画线)?
Output:<br>
Python code: 'energy' is numpy 2D array(60,736) of int32 type.
fig = plt.figure(figsize=(10, 10))
ax = fig.add_subplot(111)
plt.imshow(energy, aspect=10)
ax.axes.set_aspect(aspect=5)
plt.show()
您可以通过以下方式设置轴定位器:
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)
输出: