You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: lectures/about_py.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ Our only objective for this lecture is to give you some feel of what Python is,
53
53
54
54
Python is free and open source, with development coordinated through the [Python Software Foundation](https://www.python.org/psf/).
55
55
56
-
Python has experienced rapid adoption in the last decade and is now one of the most popular programming languages.
56
+
Python has experienced rapid adoption in the last decade and is now one of the [most popular programming languages](https://pythoncircle.com/post/763/the-rising-popularity-of-python/).
You can use the function to experiment with other styles in the list.
354
354
355
-
If you are interested, you can even create [your own style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style).
355
+
If you are interested, you can even create your own style sheets.
356
+
357
+
Parameters for your style sheets are stored in a dictionary-like variable `plt.rcParams`
358
+
359
+
```{code-cell} python3
360
+
---
361
+
tags: [hide-output]
362
+
---
363
+
364
+
print(plt.rcParams.keys())
365
+
366
+
```
367
+
368
+
There are many parameters you could set for your style sheets.
369
+
370
+
Set parameters for your style sheet by:
371
+
372
+
1. creating your own [`matplotlibrc` file](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style), or
373
+
2. updating values stored in the dictionary-like variable `plt.rcParams`
374
+
375
+
Let's change the style of our overlaid density lines using the second method
376
+
377
+
```{code-cell} python3
378
+
from cycler import cycler
379
+
380
+
# set to the default style sheet
381
+
plt.style.use('default')
382
+
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
389
+
plt.rcParams['lines.linewidth'] = 2
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
+
411
+
```
412
+
413
+
```{note}
414
+
415
+
These settings are `global`.
416
+
417
+
Any plot generated after changing parameters in `.rcParams` will be affected by the setting.
418
+
419
+
```
420
+
421
+
```{code-cell} python3
422
+
fig, ax = plt.subplots()
423
+
x = np.linspace(-4, 4, 150)
424
+
for i in range(3):
425
+
m, s = uniform(-1, 1), uniform(1, 2)
426
+
y = norm.pdf(x, loc=m, scale=s)
427
+
current_label = f'$\mu = {m:.2}$'
428
+
ax.plot(x, y, linewidth=2, alpha=0.6, label=current_label)
429
+
ax.legend()
430
+
plt.show()
431
+
```
432
+
433
+
Apply the `default` style sheet again to change your style back to default
434
+
435
+
```{code-cell} python3
436
+
437
+
plt.style.use('default')
438
+
439
+
# Reset default figure size
440
+
plt.rcParams['figure.figsize'] = (10, 6)
441
+
442
+
```
443
+
444
+
Here are [more examples](https://www.datafantic.com/the-magic-of-matplotlib-stylesheets/) on how to change these parameters.
0 commit comments