设置`axes.linewidth`而不更改`rcParams`全局字典 [英] Setting `axes.linewidth` without changing the `rcParams` global dict

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

问题描述

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

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

是否有一种简便的方法(也许可以单独设置x-和y-轴参数,等等)?

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

P.S.如果没有,为什么?

P.S. If no, why?

推荐答案

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

The above answer does not work, as it is explained in the comments. I suggest to use spines.

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

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

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