更改x轴比例im matplotlib imshow?

问题描述 投票:0回答:1

该代码给了我下面的图片。我需要在x轴上有更高的精度。现在,我每100个样本中就有下一个分数。但是我希望打印点数更多(每50个样本)。

例如(x轴:-现在我有:0 100200 ...-我要: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()
python matplotlib imshow
1个回答
1
投票

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

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

ax.plot(x,y)

输出:

enter image description here

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

ax.plot(x,y)

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

输出:

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.