This is driving me nuts.
Using matplotlib in python, I am drawing a simple plot (twenty pixels of different color) as follows:
fig1, ax = plt.subplots()
color_rgb_list = np.random.rand(n_colors, 3)
ax.imshow(color_rgb_list[None, :], aspect='equal')
for label in train_y:
ax.text(label - 1.5, 1, str(label))
plt.tight_layout()
plt.show()
# fig1.savefig("test.png", bbox_inches='tight')
However, the result I get has a lot of white space around it. I found out that I can use bbox_inches='tight'
when actually saving the figure to a file, however that does not really help me, as instead I would like to remove the white spaces while drawing the actual image.
(I am using this for an app, where I want to display several different plots in one window using tkinter with .pack()
)
How can I remove the white spaces when drawing/showing my plot?
I would basically like to achieve the same thing that bbox_inches='tight'
does, only when using plt.show()
, or when drawing on canvas using tkinter.
Thanks in advance.