设置`axes.linewidth`而不更改`rcParams`全局字典

发布于 2021-01-29 18:11:59

因此,似乎无法执行以下操作(由于axes没有set_linewidth方法,因此会引发错误):

axes_style = {'linewidth':5}
axes_rect = [0.1, 0.1, 0.9, 0.9]

axes(axes_rect, **axes_style)

并且必须使用以下旧技巧:

rcParams['axes.linewidth'] = 5 # set the value globally

... # some code

rcdefaults() # restore [global] defaults

有没有一种简单/干净的方法(也许可以单独设置x-和y-轴参数,等等)?

PS如果没有,为什么?

关注者
0
被浏览
37
1 个回答
  • 面试哥
    面试哥 2021-01-29
    为面试而生,有面试问题,就找面试哥。

    上面的答案无效,如注释中所述。我建议使用刺。

    import matplotlib.pyplot as plt
    
    fig = plt.figure()
    ax = fig.add_subplot(111)
    
    # you can change each line separately, like:
    #ax.spines['right'].set_linewidth(0.5)
    # to change all, just write:
    
    for axis in ['top','bottom','left','right']:
      ax.spines[axis].set_linewidth(0.5)
    
    plt.show()
    # see more about spines at:
    #http://matplotlib.org/api/spines_api.html
    #http://matplotlib.org/examples/pylab_examples/multiple_yaxis_with_spines.html
    


知识点
面圈网VIP题库

面圈网VIP题库全新上线,海量真题题库资源。 90大类考试,超10万份考试真题开放下载啦

去下载看看