Skip to content

Commit 76ab162

Browse files
authored
Merge pull request #221 from QuantEcon/adding-links
Adding Links and Examples for Chapter 1 and Chapter 10
2 parents 45c53ca + 7a60e85 commit 76ab162

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

lectures/about_py.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Our only objective for this lecture is to give you some feel of what Python is,
5353

5454
Python is free and open source, with development coordinated through the [Python Software Foundation](https://www.python.org/psf/).
5555

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/).
5757

5858
### Common Uses
5959

lectures/matplotlib.md

Lines changed: 91 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,97 @@ draw_graphs(style='dark_background')
352352

353353
You can use the function to experiment with other styles in the list.
354354

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.
445+
356446

357447
## Further Reading
358448

0 commit comments

Comments
 (0)