更改x轴比例im matplotlib imshow?

2024-04-20 05:00:46 发布

您现在位置:Python中文网/ 问答频道 /正文

代码给了我下面的图像。我需要在x轴上有更高的精度。现在每100个样本中就有下一个点。但我希望印刷点更经常(每50个样品)。你知道吗

例如(x轴): -现在我有:0 100 200。。。 -我要:0 50 100 150 200。。。你知道吗

有没有可能在这个图像上用一个网格来制作这个图像(在两个轴(x和y)的每个打印点上画线)?你知道吗

Output:<br>

output

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()

Tags: 代码图像br网格output样品fig精度
1条回答
网友
1楼 · 发布于 2024-04-20 05:00:46

可以按以下方式设置轴定位器:

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

相关问题 更多 >