From 8fc08cce902de74652ac9892e3d6b73075e1c9fd Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 20:52:41 +1000 Subject: [PATCH 01/21] update stylesheet --- lectures/matplotlib.md | 45 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 051c8c83..45a6d0c6 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -268,6 +268,51 @@ The custom `subplots` function 1. makes the desired customizations to `ax`, and 1. passes the `fig, ax` pair back to the calling code. +### Style Sheets + +Another useful feature in Matplotlib is [style sheet](https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html). + +We can use style sheets to create plots with uniform styles. + +We can find a list of available style sheets by printing the attribute `plt.style.available`. + + +```{code-cell} python3 +print(plt.style.available) +``` + +Let's apply some of them to different types of visualizations + +```{code-cell} python3 + +# Use four different style sheets +styles = ['seaborn', 'grayscale', 'ggplot', 'dark_background'] + +for i in range(4): + + # Set style sheet + plt.style.use(styles[i]) + + fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3)) + x = np.linspace(-12, 12, 150) + current_label = f'$\mu = {m:.2}$' + + for j in range(3): + m, s = uniform(-10, 10), uniform(1, 2) + y = norm.pdf(x, loc=m, scale=s) + rnormX = norm.rvs(loc=m, scale=s, size=150) + rnormY = norm.rvs(loc=m, scale=s, size=150) + axes[0].plot(x, y, linewidth=3) + axes[1].plot(rnormX, rnormY, ls='none', marker='o') + axes[2].hist(rnormX) + axes[3].plot(x, rnormY, linewidth=2) + + plt.title(f'Style: {styles[i]}', fontsize=11) + +plt.show() + +``` + ## Further Reading * The [Matplotlib gallery](http://matplotlib.org/gallery.html) provides many examples. From d9a98959c17cf45433cd4fe862b57e70176dee82 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 21:15:55 +1000 Subject: [PATCH 02/21] adding link for creating new style sheet --- lectures/matplotlib.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 45a6d0c6..d8e5134e 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -281,7 +281,7 @@ We can find a list of available style sheets by printing the attribute `plt.styl print(plt.style.available) ``` -Let's apply some of them to different types of visualizations +Let's apply some of them to different types of graphs ```{code-cell} python3 @@ -313,6 +313,8 @@ plt.show() ``` +We can also create [our own style sheet](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). + ## Further Reading * The [Matplotlib gallery](http://matplotlib.org/gallery.html) provides many examples. From baee44c33685fc9e705e173d43877d2ff398946d Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 21:19:45 +1000 Subject: [PATCH 03/21] fix a full stop --- lectures/matplotlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index d8e5134e..33651d51 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -274,7 +274,7 @@ Another useful feature in Matplotlib is [style sheet](https://matplotlib.org/sta We can use style sheets to create plots with uniform styles. -We can find a list of available style sheets by printing the attribute `plt.style.available`. +We can find a list of available style sheets by printing the attribute `plt.style.available` ```{code-cell} python3 From 6f0eead85410d96c7d7c1eda2f730a1d1a6ca6ec Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 21:22:08 +1000 Subject: [PATCH 04/21] increase the width of the graph --- lectures/matplotlib.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 33651d51..d778a754 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -293,8 +293,8 @@ for i in range(4): # Set style sheet plt.style.use(styles[i]) - fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3)) - x = np.linspace(-12, 12, 150) + fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(13, 3)) + x = np.linspace(-13, 13, 150) current_label = f'$\mu = {m:.2}$' for j in range(3): From 57a764e79c435e4ccecf8a053150d1db3f85c70e Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 21:33:01 +1000 Subject: [PATCH 05/21] update DIY sentence --- lectures/matplotlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index d778a754..a64911d5 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -313,7 +313,7 @@ plt.show() ``` -We can also create [our own style sheet](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). +If you are interested, you can also create [our own style sheet](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). ## Further Reading From 165d45050e49b610528470e4640e7454a52e4aa1 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 21:44:52 +1000 Subject: [PATCH 06/21] fix typo --- lectures/matplotlib.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index a64911d5..17d6b0d3 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -270,7 +270,7 @@ The custom `subplots` function ### Style Sheets -Another useful feature in Matplotlib is [style sheet](https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html). +Another useful feature in Matplotlib is [style sheets](https://matplotlib.org/stable/gallery/style_sheets/style_sheets_reference.html). We can use style sheets to create plots with uniform styles. @@ -313,7 +313,7 @@ plt.show() ``` -If you are interested, you can also create [our own style sheet](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). +If you are interested, you can also create [our own style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). ## Further Reading From 0e3b083ef6e7af57862edf30d2f9784dda70d93d Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Fri, 26 Aug 2022 21:48:12 +1000 Subject: [PATCH 07/21] adding alpha --- lectures/matplotlib.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 17d6b0d3..927ad128 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -302,10 +302,10 @@ for i in range(4): y = norm.pdf(x, loc=m, scale=s) rnormX = norm.rvs(loc=m, scale=s, size=150) rnormY = norm.rvs(loc=m, scale=s, size=150) - axes[0].plot(x, y, linewidth=3) - axes[1].plot(rnormX, rnormY, ls='none', marker='o') - axes[2].hist(rnormX) - axes[3].plot(x, rnormY, linewidth=2) + axes[0].plot(x, y, linewidth=3, alpha = 0.7) + axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha = 0.7) + axes[2].hist(rnormX, alpha = 0.7) + axes[3].plot(x, rnormY, linewidth=2, alpha = 0.7) plt.title(f'Style: {styles[i]}', fontsize=11) From 6d6be0e025fadf752dcd9561c28445d32aaeef33 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 12:07:43 +1000 Subject: [PATCH 08/21] center title and change size --- lectures/matplotlib.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 927ad128..0f7c0b8f 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -293,7 +293,7 @@ for i in range(4): # Set style sheet plt.style.use(styles[i]) - fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(13, 3)) + fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3)) x = np.linspace(-13, 13, 150) current_label = f'$\mu = {m:.2}$' @@ -307,7 +307,7 @@ for i in range(4): axes[2].hist(rnormX, alpha = 0.7) axes[3].plot(x, rnormY, linewidth=2, alpha = 0.7) - plt.title(f'Style: {styles[i]}', fontsize=11) + plt.suptitle(f'Style: {styles[i]}', fontsize=13) plt.show() From c414fe493bc8732e6059b389acc2fcc078976fb8 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 15:48:03 +1000 Subject: [PATCH 09/21] add function and seed --- lectures/matplotlib.md | 53 +++++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 13 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 0f7c0b8f..7e34bd6d 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -281,39 +281,66 @@ We can find a list of available style sheets by printing the attribute `plt.styl print(plt.style.available) ``` -Let's apply some of them to different types of graphs +let's write a function that draws different types of graphs with a given style sheet -```{code-cell} python3 +We can use `plt.style.use` function to set style sheet. -# Use four different style sheets -styles = ['seaborn', 'grayscale', 'ggplot', 'dark_background'] +```{code-cell} python3 +import random -for i in range(4): +def draw_graphs(style = 'default'): - # Set style sheet - plt.style.use(styles[i]) + # Setting a style sheet + plt.style.use(style) fig, axes = plt.subplots(nrows=1, ncols=4, figsize=(10, 3)) x = np.linspace(-13, 13, 150) - current_label = f'$\mu = {m:.2}$' - for j in range(3): + # Set seed values to replicate results of random draws + random.seed(1) + np.random.seed(1) + + for i in range(3): + + # Draw mean and standard deviation from uniform distributions m, s = uniform(-10, 10), uniform(1, 2) + + # Generate a normal density plot y = norm.pdf(x, loc=m, scale=s) + axes[0].plot(x, y, linewidth=3, alpha = 0.7) + + # create a scatter plot with random X and Y values + # from normal distributions rnormX = norm.rvs(loc=m, scale=s, size=150) rnormY = norm.rvs(loc=m, scale=s, size=150) - axes[0].plot(x, y, linewidth=3, alpha = 0.7) axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha = 0.7) + + # a histogram with random X axes[2].hist(rnormX, alpha = 0.7) + + # and a line graph with random Y axes[3].plot(x, rnormY, linewidth=2, alpha = 0.7) - plt.suptitle(f'Style: {styles[i]}', fontsize=13) + plt.suptitle(f'Style: {style}', fontsize=13) + plt.show() -plt.show() +``` + +Let's see what some of the styles look like + +```{code-cell} python3 + +# Use four different style sheets +draw_graphs(style = 'seaborn') +draw_graphs(style = 'grayscale') +draw_graphs(style = 'ggplot') +draw_graphs(style = 'dark_background') ``` -If you are interested, you can also create [our own style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). +You can use the function to experiment with more styles. + +If you are interested, you can even create [our own style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). ## Further Reading From 4f3f1417f8b6f95133ecde0a3a684add7ab6af89 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 18:55:57 +1000 Subject: [PATCH 10/21] update based on review --- lectures/matplotlib.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 7e34bd6d..08af5386 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -281,7 +281,7 @@ We can find a list of available style sheets by printing the attribute `plt.styl print(plt.style.available) ``` -let's write a function that draws different types of graphs with a given style sheet +Let's write a function that draws different types of graphs with a given style sheet We can use `plt.style.use` function to set style sheet. @@ -298,7 +298,6 @@ def draw_graphs(style = 'default'): # Set seed values to replicate results of random draws random.seed(1) - np.random.seed(1) for i in range(3): @@ -332,8 +331,11 @@ Let's see what some of the styles look like # Use four different style sheets draw_graphs(style = 'seaborn') + draw_graphs(style = 'grayscale') + draw_graphs(style = 'ggplot') + draw_graphs(style = 'dark_background') ``` From 0ff8ef407fb5ac1452454ea0cefd9fce36fb7aa4 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 19:07:27 +1000 Subject: [PATCH 11/21] fix typo --- lectures/matplotlib.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 08af5386..53e1ab01 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -280,11 +280,10 @@ We can find a list of available style sheets by printing the attribute `plt.styl ```{code-cell} python3 print(plt.style.available) ``` +We can also use the `plt.style.use()` method to set style sheet. Let's write a function that draws different types of graphs with a given style sheet -We can use `plt.style.use` function to set style sheet. - ```{code-cell} python3 import random From 6271666464cbf51c577a2b04762ff690c2500c46 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 19:10:05 +1000 Subject: [PATCH 12/21] fix typos --- lectures/matplotlib.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 53e1ab01..4f3e2a0d 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -307,16 +307,16 @@ def draw_graphs(style = 'default'): y = norm.pdf(x, loc=m, scale=s) axes[0].plot(x, y, linewidth=3, alpha = 0.7) - # create a scatter plot with random X and Y values + # Create a scatter plot with random X and Y values # from normal distributions rnormX = norm.rvs(loc=m, scale=s, size=150) rnormY = norm.rvs(loc=m, scale=s, size=150) axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha = 0.7) - # a histogram with random X + # a histogram with X axes[2].hist(rnormX, alpha = 0.7) - # and a line graph with random Y + # and a line graph with Y axes[3].plot(x, rnormY, linewidth=2, alpha = 0.7) plt.suptitle(f'Style: {style}', fontsize=13) From 3095ff0fea4d8f4dfe286df17999e2fbbf08ed56 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 19:14:47 +1000 Subject: [PATCH 13/21] fix spacing --- lectures/matplotlib.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 4f3e2a0d..b8563ce6 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -287,7 +287,7 @@ Let's write a function that draws different types of graphs with a given style s ```{code-cell} python3 import random -def draw_graphs(style = 'default'): +def draw_graphs(style='default'): # Setting a style sheet plt.style.use(style) @@ -305,7 +305,7 @@ def draw_graphs(style = 'default'): # Generate a normal density plot y = norm.pdf(x, loc=m, scale=s) - axes[0].plot(x, y, linewidth=3, alpha = 0.7) + axes[0].plot(x, y, linewidth=3, alpha=0.7) # Create a scatter plot with random X and Y values # from normal distributions @@ -314,10 +314,10 @@ def draw_graphs(style = 'default'): axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha = 0.7) # a histogram with X - axes[2].hist(rnormX, alpha = 0.7) + axes[2].hist(rnormX, alpha=0.7) # and a line graph with Y - axes[3].plot(x, rnormY, linewidth=2, alpha = 0.7) + axes[3].plot(x, rnormY, linewidth=2, alpha=0.7) plt.suptitle(f'Style: {style}', fontsize=13) plt.show() @@ -329,13 +329,14 @@ Let's see what some of the styles look like ```{code-cell} python3 # Use four different style sheets -draw_graphs(style = 'seaborn') -draw_graphs(style = 'grayscale') +draw_graphs(style='seaborn') -draw_graphs(style = 'ggplot') +draw_graphs(style='grayscale') -draw_graphs(style = 'dark_background') +draw_graphs(style='ggplot') + +draw_graphs(style='dark_background') ``` From 73a2d373f72f59f0178956597b684c5574285689 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 19:37:27 +1000 Subject: [PATCH 14/21] update parameters and np.random --- lectures/matplotlib.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index b8563ce6..bac6e38e 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -285,7 +285,6 @@ We can also use the `plt.style.use()` method to set style sheet. Let's write a function that draws different types of graphs with a given style sheet ```{code-cell} python3 -import random def draw_graphs(style='default'): @@ -296,12 +295,12 @@ def draw_graphs(style='default'): x = np.linspace(-13, 13, 150) # Set seed values to replicate results of random draws - random.seed(1) + np.random.seed(9) for i in range(3): # Draw mean and standard deviation from uniform distributions - m, s = uniform(-10, 10), uniform(1, 2) + m, s = np.random.uniform(-8, 8), np.random.uniform(2, 2.5) # Generate a normal density plot y = norm.pdf(x, loc=m, scale=s) From 77113cd334ea407c8a94db4522a4628eb8c98e95 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 19:39:12 +1000 Subject: [PATCH 15/21] fix typo --- lectures/matplotlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index bac6e38e..26bc0d87 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -310,7 +310,7 @@ def draw_graphs(style='default'): # from normal distributions rnormX = norm.rvs(loc=m, scale=s, size=150) rnormY = norm.rvs(loc=m, scale=s, size=150) - axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha = 0.7) + axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha=0.7) # a histogram with X axes[2].hist(rnormX, alpha=0.7) From 263842239e6cd2e1d6924b11b2672ce6b674f532 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Mon, 29 Aug 2022 19:40:55 +1000 Subject: [PATCH 16/21] remove spacing --- lectures/matplotlib.md | 1 - 1 file changed, 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 26bc0d87..836fa58c 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -328,7 +328,6 @@ Let's see what some of the styles look like ```{code-cell} python3 # Use four different style sheets - draw_graphs(style='seaborn') draw_graphs(style='grayscale') From c549829664c08505498210722dcdc97bb327e114 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 30 Aug 2022 09:04:58 +1000 Subject: [PATCH 17/21] seperate cells --- lectures/matplotlib.md | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 836fa58c..f8c763f5 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -323,19 +323,30 @@ def draw_graphs(style='default'): ``` -Let's see what some of the styles look like +Let's see what some of the styles look like. -```{code-cell} python3 +First, we draw graphs with the style sheet `seaborn` -# Use four different style sheets +```{code-cell} python3 draw_graphs(style='seaborn') +``` +Then, we can use `grayscale` to remove colors + +```{code-cell} python3 draw_graphs(style='grayscale') +``` +Here is what `ggplot` looks like + +```{code-cell} python3 draw_graphs(style='ggplot') +``` -draw_graphs(style='dark_background') +We can also use the style `dark_background` +```{code-cell} python3 +draw_graphs(style='dark_background') ``` You can use the function to experiment with more styles. From 9c7470f225619120ae60278950d690886ce0ca57 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 30 Aug 2022 09:52:14 +1000 Subject: [PATCH 18/21] fix typo --- lectures/matplotlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index f8c763f5..33545f15 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -280,7 +280,7 @@ We can find a list of available style sheets by printing the attribute `plt.styl ```{code-cell} python3 print(plt.style.available) ``` -We can also use the `plt.style.use()` method to set style sheet. +We can also use the `plt.style.use()` method to set the style sheet. Let's write a function that draws different types of graphs with a given style sheet From 02744e5408619b2acd539d360cfce3c148fdb6f9 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 30 Aug 2022 17:05:02 +1000 Subject: [PATCH 19/21] change wording --- lectures/matplotlib.md | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 33545f15..b431b4c2 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -274,15 +274,16 @@ Another useful feature in Matplotlib is [style sheets](https://matplotlib.org/st We can use style sheets to create plots with uniform styles. -We can find a list of available style sheets by printing the attribute `plt.style.available` +We can find a list of available styles by printing the attribute `plt.style.available` ```{code-cell} python3 print(plt.style.available) ``` -We can also use the `plt.style.use()` method to set the style sheet. -Let's write a function that draws different types of graphs with a given style sheet +We can now use the `plt.style.use()` method to set the style sheet. + +Let's write a function that takes the name of a style sheet and draws different plots with the style ```{code-cell} python3 @@ -312,10 +313,10 @@ def draw_graphs(style='default'): rnormY = norm.rvs(loc=m, scale=s, size=150) axes[1].plot(rnormX, rnormY, ls='none', marker='o', alpha=0.7) - # a histogram with X + # Create a histogram with random X values axes[2].hist(rnormX, alpha=0.7) - # and a line graph with Y + # and a line graph with random Y values axes[3].plot(x, rnormY, linewidth=2, alpha=0.7) plt.suptitle(f'Style: {style}', fontsize=13) @@ -331,7 +332,7 @@ First, we draw graphs with the style sheet `seaborn` draw_graphs(style='seaborn') ``` -Then, we can use `grayscale` to remove colors +We can use `grayscale` to remove colors in plots ```{code-cell} python3 draw_graphs(style='grayscale') @@ -349,9 +350,9 @@ We can also use the style `dark_background` draw_graphs(style='dark_background') ``` -You can use the function to experiment with more styles. +You can use the function to experiment with other styles in the list. -If you are interested, you can even create [our own style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). +If you are interested, you can even create [your own style sheets](https://matplotlib.org/stable/tutorials/introductory/customizing.html#defining-your-own-style). ## Further Reading From cecfe5da132b4b8e72d30ea75535ebec4a279d66 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 30 Aug 2022 17:38:47 +1000 Subject: [PATCH 20/21] change typo --- lectures/matplotlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index b431b4c2..61608a8b 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -283,7 +283,7 @@ print(plt.style.available) We can now use the `plt.style.use()` method to set the style sheet. -Let's write a function that takes the name of a style sheet and draws different plots with the style +Let's write a function that takes the name of a style sheet and draws different plots with the same style ```{code-cell} python3 From d69d73574453aacfbbb3179897e473153b2369a9 Mon Sep 17 00:00:00 2001 From: Humphrey Yang Date: Tue, 30 Aug 2022 17:39:38 +1000 Subject: [PATCH 21/21] Revert "change typo" This reverts commit cecfe5da132b4b8e72d30ea75535ebec4a279d66. --- lectures/matplotlib.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lectures/matplotlib.md b/lectures/matplotlib.md index 61608a8b..b431b4c2 100644 --- a/lectures/matplotlib.md +++ b/lectures/matplotlib.md @@ -283,7 +283,7 @@ print(plt.style.available) We can now use the `plt.style.use()` method to set the style sheet. -Let's write a function that takes the name of a style sheet and draws different plots with the same style +Let's write a function that takes the name of a style sheet and draws different plots with the style ```{code-cell} python3