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 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.