Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7ff1611

Browse files
committed
Prefer demo'ing rcParams rather than rc in examples.
If you know how to set to rcParams (which is "just a dict"), you'll figure out how to read from it as well. The ability of save a few keystrokes in rc() is not worth the different API -- at least for the example.
1 parent 9ccdb1d commit 7ff1611

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

examples/misc/customize_rc.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,16 @@
1212
functions in a custom module that set the defaults, e.g.,::
1313
1414
def set_pub():
15-
rc('font', weight='bold') # bold fonts are easier to see
16-
rc('tick', labelsize=15) # tick labels bigger
17-
rc('lines', lw=1, color='k') # thicker black lines
18-
rc('grid', c='0.5', ls='-', lw=0.5) # solid gray grid lines
19-
rc('savefig', dpi=300) # higher res outputs
15+
rcParams.update({
16+
"font.weight": "bold", # bold fonts
17+
"tick.labelsize": 15, # large tick labels
18+
"lines.linewidth": 1, # thick lines
19+
"lines.color": "k", # black lines
20+
"grid.color": "0.5", # gray gridlines
21+
"grid.linestyle": "-", # solid gridlines
22+
"grid.linewidth": 0.5, # thin gridlines
23+
"savefig.dpi": 300, # higher resolution output.
24+
})
2025
2126
Then as you are working interactively, you just need to do::
2227
@@ -33,15 +38,18 @@ def set_pub():
3338
plt.plot([1, 2, 3])
3439

3540
# the axes attributes need to be set before the call to subplot
36-
plt.rc('font', weight='bold')
37-
plt.rc('xtick.major', size=5, pad=7)
38-
plt.rc('xtick', labelsize=15)
39-
40-
# using aliases for color, linestyle and linewidth; gray, solid, thick
41-
plt.rc('grid', c='0.5', ls='-', lw=5)
42-
plt.rc('lines', lw=2, color='g')
41+
plt.rcParams.update({
42+
"font.weight": "bold",
43+
"xtick.major.size": 5,
44+
"xtick.major.pad": 7,
45+
"xtick.labelsize": 15,
46+
"grid.color": "0.5",
47+
"grid.linestyle": "-",
48+
"grid.linewidth": 5,
49+
"lines.linewidth": 2,
50+
"lines.color": "g",
51+
})
4352
plt.subplot(312)
44-
4553
plt.plot([1, 2, 3])
4654
plt.grid(True)
4755

0 commit comments

Comments
 (0)