How to draw a frame on a matplotlib figure

前端 未结 2 741
被撕碎了的回忆
被撕碎了的回忆 2021-02-09 18:58

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         


        
2条回答
  •  耶瑟儿~
    2021-02-09 19:53

    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.

提交回复
热议问题