librosa.display.specshow中的小边框

时间:2018-01-15 14:17:29

标签: matplotlib librosa

我想绘制一首歌曲的频谱图,用作卷积神经网络的图像分类功能。因此,输出图像必须尽可能干净,没有任何标签/轴/刻度等。

从各种来源,我设法通过在box_inches=tight方法上设置plt.savefig来禁用matplotlib默认绘制的边框。尽管如此,我试图绘制的任何图像上都有一个小边框。

此示例代码不使用实际音频文件,但仍然可以看到小边框:

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import librosa
import librosa.display
import numpy as np

plt.axis('off')
S = np.array([[1,2,3], [2,2,1], [3,1,3]])
librosa.display.specshow(S)  # i suspect this method to somehow draw the border
plt.margins(0)  # as suggested by Eran W
plt.savefig('test.png', transparent=False, bbox_inches='tight', pad_inches=0)
plt.close()

plot with a small white border that I don't like

我在the official documentations中找不到该方法的任何内容,也不知道如何调试此问题。任何提示?

2 个答案:

答案 0 :(得分:0)

您可以通过调用:

通过matplotlib设置边距
plt.margins(0)

docs:https://matplotlib.org/devdocs/api/_as_gen/matplotlib.pyplot.margins.html

答案 1 :(得分:0)

我遇到了同样的问题,我找到了这个示例代码:

newPanel.setLocationRelativeTo(parentPanel);
相关问题