Skip to content

Commit 7a60e85

Browse files
committed
add a more convenient method
1 parent 6555f39 commit 7a60e85

File tree

1 file changed

+29
-11
lines changed

1 file changed

+29
-11
lines changed

lectures/matplotlib.md

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,24 +372,42 @@ Set parameters for your style sheet by:
372372
1. creating your own [`matplotlibrc` file](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style), or
373373
2. updating values stored in the dictionary-like variable `plt.rcParams`
374374

375-
Let's change the style of our overlaid density lines
375+
Let's change the style of our overlaid density lines using the second method
376376

377377
```{code-cell} python3
378378
from cycler import cycler
379379
380380
# set to the default style sheet
381381
plt.style.use('default')
382382
383-
#set default figure size
384-
plt.rcParams['figure.figsize'] = (10, 6)
385-
# update linewidth
383+
# You can update single values using keys:
384+
385+
# Set the font style to italic
386+
plt.rcParams['font.style'] = 'italic'
387+
388+
# Update linewidth
386389
plt.rcParams['lines.linewidth'] = 2
387-
# add horizontal grid lines
388-
plt.rcParams['axes.grid'] = True
389-
plt.rcParams['axes.grid.axis'] = 'y'
390-
# update colors for density lines
391-
plt.rcParams['axes.prop_cycle'] = cycler('color',
392-
['dimgray', 'slategrey', 'darkgray'])
390+
391+
392+
# You can also update many values at once using the update() method:
393+
394+
parameters = {
395+
396+
# Change default figure size
397+
'figure.figsize': (5, 4),
398+
399+
# Add horizontal grid lines
400+
'axes.grid': True,
401+
'axes.grid.axis': 'y',
402+
403+
# Update colors for density lines
404+
'axes.prop_cycle': cycler('color',
405+
['dimgray', 'slategrey', 'darkgray'])
406+
}
407+
408+
plt.rcParams.update(parameters)
409+
410+
393411
```
394412

395413
```{note}
@@ -418,7 +436,7 @@ Apply the `default` style sheet again to change your style back to default
418436
419437
plt.style.use('default')
420438
421-
#set default figure size
439+
# Reset default figure size
422440
plt.rcParams['figure.figsize'] = (10, 6)
423441
424442
```

0 commit comments

Comments
 (0)