matplotlib savefig裁剪最后一行和最后一列

2024-04-25 19:24:25 发布

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

当我使用节目()我得到了整个迷宫,而当我使用savefig保存同一个图像时,最后一行和正在绘制的列会被裁剪/切断。你知道吗

这是用来绘制迷宫的代码。(我附上了迷宫的截图。)

def maze_plot_final(maze):
    fig, ax = plt.subplots()
    ax.cla()
    cmap = plt.cm.get_cmap()
    cmap.set_bad("white")
    ax.imshow(maze, cmap=cmap)
    plt.savefig('figs/dfs-new.png', dpi=1000, bbox_inches='tight',)

The entire maze traversed

This is the screenshot of the image generated by savefig

This is the screenshot of the last part of maze shown by plt.show


Tags: ofthe图像byis绘制pltax
1条回答
网友
1楼 · 发布于 2024-04-25 19:24:25

在保存之前您是否尝试过设置轴限制?你知道吗

plt.xlim(tuple_x)
plt.ylim(tuple_y)

其中tuple_x:

(x0,xf) := interval of interest

相关问题 更多 >