Matplotlib:更改所有子图的线宽

10

我正在使用matplotlib(版本1.3.1)和Python 2.7绘制一个子图网格(6x2)。我设置了我的图形并在子图中绘制如下:

fig, axes = plt.subplots(ncols=6, nrows=2, 
                         sharex=True, sharey=True, figsize=(30,5))

axes[0,0].plot(x, y)
axes[1,5].plot(z, a)

我有一个问题:是否有一种方法可以同时更改所有这些图的线条属性?我可以在每个轴上手动指定axes[0,0].plot(x,y,'k',linewidth=2.0),但我认为必须有一种方法可以同时对所有12个图进行操作。
祝好。

7
您可以使用 mpl.rc('lines', linewidth=2.0),不确定是否比在每次调用时明确编写更好。 - cel
1
@cel 谢谢。这对于linewidth有效,但是为什么“mplr.rc('lines', color='black')”没有起作用呢? - thosphor
2
有趣的问题。文档声称它应该可以工作。但是在这里似乎也无法工作。http://matplotlib.org/1.4.1/users/customizing.html#dynamic-rc-settings - cel
2
参见:https://github.com/matplotlib/matplotlib/issues/4047 - cel
@cel Github上的解决方案对我很有用。 - thosphor
最终使用了 plt.rc('lines', linewidth=2.0)... - PatrickT
2个回答

11

试试这个:

import matplotlib as mpl
mpl.rcParams['lines.linewidth'] = 2

这应该动态地改变默认的matplotlibrc配置。

编辑:算了,已经在您的问题评论中提到了。


谢谢。这对于线宽度起作用了,但是为什么“mplr.rc('lines', color='black')”没有起作用呢? - thosphor
“copied”这个词听起来好像是有意的。我想我只是比较快 :) - cel
1
@cel 抱歉,我的评论是从上面复制的。我并不是在指责安德烈亚斯抄袭。 - thosphor

1

在我的Jupyter笔记本中,我执行以下操作

%matplotlib inline
# plt.style.use('fivethirtyeight')                # first, small enchancements, xlabels, ylabels, legand sizing...   
plt.rcParams['lines.linewidth'] = 2               # Change linewidth of plots
# plt.rcParams['figure.figsize'] = (12, 8)        # Change the size of plots

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接