I want to show the frame in this figure. I tried running the code below but it didnt work :
ax = self.canvas.figure.add_subplot(111)
ax.spines[\'top\'].set_vis
The borders (or spines) are already visible, but white. You need to change the color as explained in this response: https://stackoverflow.com/a/43265998/1773344
example for some kind of gray:
ax.spines['bottom'].set_color('0.5')
ax.spines['top'].set_color('0.5')
ax.spines['right'].set_color('0.5')
ax.spines['left'].set_color('0.5')
If you want the borders AROUND the axes, there is no simple solution. Except perhaps putting your axis inside an axis with adjusted borders as partially explained in this answer: https://stackoverflow.com/a/22608025/1773344
The main point is that you seem to be using seaborn or at least the seaborn darkgrid style. If this is indeed desired, but you still want a border around the axes, you need to change the style.
plt.rcParams["axes.edgecolor"] = "black"
plt.rcParams["axes.linewidth"] = 1
This is (as @Wli mentions) explained in this answer.
This is all independent of tight_layout
. The reason why plt.tight_layout()
produces the error shown cannot be determined for sure with the information at hand. However, you might in general be better off calling the figure's method than using pyplot
in the GUI. SO you may try self.canvas.figure.tight_layout()
instead.