Skip to content

Commit 1bcfbdd

Browse files
committed
update the default setup
1 parent 2324ee0 commit 1bcfbdd

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

lectures/matplotlib.md

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ You can use the function to experiment with other styles in the list.
354354

355355
If you are interested, you can even create your own style sheets.
356356

357-
Paraeters for your style sheets are stored in a dictionary-like variable `plt.rcParams`
357+
Parameters for your style sheets are stored in a dictionary-like variable `plt.rcParams`
358358

359359
```{code-cell} python3
360360
---
@@ -380,14 +380,27 @@ from cycler import cycler
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)
383385
# update linewidth
384386
plt.rcParams['lines.linewidth'] = 2
385387
# add horizontal grid lines
386388
plt.rcParams['axes.grid'] = True
387389
plt.rcParams['axes.grid.axis'] = 'y'
388390
# update colors for density lines
389-
plt.rcParams['axes.prop_cycle'] = cycler('color', ['dimgray', 'slategrey', 'darkgray'])
391+
plt.rcParams['axes.prop_cycle'] = cycler('color',
392+
['dimgray', 'slategrey', 'darkgray'])
393+
```
394+
395+
```{note}
396+
397+
These settings are `global`.
398+
399+
Any plot generated after changing parameters in `.rcParams` will be affected by the setting.
390400
401+
```
402+
403+
```{code-cell} python3
391404
fig, ax = plt.subplots()
392405
x = np.linspace(-4, 4, 150)
393406
for i in range(3):
@@ -397,11 +410,22 @@ for i in range(3):
397410
ax.plot(x, y, linewidth=2, alpha=0.6, label=current_label)
398411
ax.legend()
399412
plt.show()
413+
```
414+
415+
Apply the `default` style sheet again to change your style back to default
416+
417+
```{code-cell} python3
418+
419+
plt.style.use('default')
420+
421+
#set default figure size
422+
plt.rcParams["figure.figsize"] = (10, 6)
400423
401424
```
402425

403426
Here are [more examples](https://www.datafantic.com/the-magic-of-matplotlib-stylesheets/) on how to change these parameters.
404427

428+
405429
## Further Reading
406430

407431
* The [Matplotlib gallery](http://matplotlib.org/gallery.html) provides many examples.

0 commit comments

Comments
 (0)