在不更改 rcParams 全局字典的情况下设置 axes.linewidth [英] Setting axes.linewidth without changing the rcParams global dict

查看:24
本文介绍了在不更改 rcParams 全局字典的情况下设置 axes.linewidth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

因此,似乎不能执行以下操作(它会引发错误,因为 axes 没有 set_linewidth 方法):

axes_style = {'linewidth':5}axis_rect = [0.1, 0.1, 0.9, 0.9]轴(axes_rect,**axes_style)

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

rcParams['axes.linewidth'] = 5 # 全局设置值... # 一些代码rcdefaults() # 恢复 [全局] 默认值

是否有一种简单/干净的方法(可能可以单独设置 x- 和 y- 轴参数等)?

如果不是,为什么?

解决方案

  • So, it seems one cannot do the following (it raises an error, since axes does not have a set_linewidth method):

    axes_style = {'linewidth':5}
    axes_rect = [0.1, 0.1, 0.9, 0.9]
    
    axes(axes_rect, **axes_style)
    

    and has to use the following old trick instead:

    rcParams['axes.linewidth'] = 5 # set the value globally
    
    ... # some code
    
    rcdefaults() # restore [global] defaults
    

    Is there an easy / clean way (may be one can set x- and y- axes parameters individually, etc)?

    If no, why?

    解决方案

    • This answer does not work, as it is explained in the comments. I suggest using spines.
    • As mentioned in a comment by Czechnology, consider changing the ticks too.

    import matplotlib.pyplot as plt
    
    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(10, 4))
    
    ax1.set_title('Normal spine and ticks')
    ax2.set_title('Adjusted spine and ticks')
    
    # change each spine separately:
    # ax.spines['right'].set_linewidth(0.5)
    
    # change all spines
    for axis in ['top','bottom','left','right']:
        ax2.spines[axis].set_linewidth(4)
    
    # increase tick width
    ax2.tick_params(width=4)
    
    plt.show()
    

    这篇关于在不更改 rcParams 全局字典的情况下设置 axes.linewidth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆