9

I'm plotting a grid of subplots (6x2) with matplotlib (version 1.3.1) and Python 2.7. I set up my figure and plot things in the subplots like this:

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)

etc.

My question is this: is there a way to change the line properties on all of these plots at once? I could manually specify axes[0,0].plot(x,y,'k',linewidth=2.0) on each of the axes, but I thought there must be a way to do it for all 12 plots at once.

Cheers.

thosphor
  • 2,493
  • 7
  • 26
  • 42
  • 7
    You can use `mpl.rc('lines', linewidth=2.0)`, not sure if I would prefer that over explicitly writing it in each call, though. – cel Jan 28 '15 at 12:00
  • 1
    @cel Thanks. That worked for linewidth, but why didn't ``mplr.rc('lines', color='black')`` work? – thosphor Jan 28 '15 at 12:04
  • 2
    Interesting question. the docs claim that is should work. But it does not seem to work here either. http://matplotlib.org/1.4.1/users/customizing.html#dynamic-rc-settings – cel Jan 28 '15 at 12:09
  • 2
    See also: https://github.com/matplotlib/matplotlib/issues/4047 – cel Jan 28 '15 at 15:15
  • @cel The solution on github worked for me. – thosphor Jan 28 '15 at 15:58
  • ended up with `plt.rc('lines', linewidth=2.0)`... – PatrickT Jan 03 '22 at 11:54

2 Answers2

10

Try this:

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

This should dynamically change the default matplotlibrc configuration.

Edit: nevermind, already mentioned in the comments to your question.

dudenr33
  • 1,119
  • 1
  • 10
  • 26
  • Comment copied from above: Thanks. That worked for linewidth, but why didn't ``mplr.rc('lines', color='black')`` work? – thosphor Jan 28 '15 at 12:05
  • The word `copied` makes it sound as if that was intentional. I guess I was just faster :) – cel Jan 28 '15 at 12:11
  • 1
    @cel Sorry I meant my comment was copied from above. I wasn't accusing Andreas of copying. – thosphor Jan 28 '15 at 13:23
0

In my Jupyter notebook I do

%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
Ali Pardhan
  • 194
  • 1
  • 14