@@ -86,44 +86,34 @@ Tetralith |`module load buildtool-easybuild/4.8.0-hpce082752a2 GCC/13.2.0 Pytho
8686
8787## Exercises
8888
89- ``` python
90- import matplotlib.pyplot as plt
91- plt.style.use(' classic' )
92- % matplotlib inline
93- import numpy as np
94- import seaborn as pd
95-
96- # Create some data
97- rng = np.random.RandomState(0 )
98- x = np.linspace(0 , 10 , 500 )
99- y = np.cumsum(rng.randn(500 , 6 ), 0 )
100-
101- # Plot the data with Matplotlib defaults
102- plt.plot(x, y)
103- plt.legend(' ABCDEF' , ncol = 2 , loc = ' upper left' );
104-
89+ Run the following code, that is copied from
90+ [ the ` seaborn ` page 'An introduction to ` seaborn ` '] ( https://seaborn.pydata.org/tutorial/introduction.html )
91+ and combined with
92+ [ this StackOverflow post to save it to a file] ( https://stackoverflow.com/a/39482402/3364162 )
10593
94+ ``` python
95+ # Import seaborn
10696import seaborn as sns
107- sns.set()
10897
98+ # Apply the default theme
99+ sns.set_theme()
109100
110- # same plotting code as above!
111- plt.plot(x, y)
112- plt.legend(' ABCDEF' , ncol = 2 , loc = ' upper left' );
113- ```
114-
115- ``` python
116- data = np.random.multivariate_normal([0 , 0 ], [[5 , 2 ], [2 , 2 ]], size = 2000 )
117- data = pd.DataFrame(data, columns = [' x' , ' y' ])
101+ # Load an example dataset
102+ tips = sns.load_dataset(" tips" )
118103
119- # Two overlaid density plots
120- for col in ' xy' :
121- sns.kdeplot(data[col], shade = True )
122-
123- # Density plot
124- sns.kdeplot(data);
104+ # Create a visualization and save it to file
105+ my_plot = sns.relplot(
106+ data = tips,
107+ x = " total_bill" , y = " tip" , col = " time" ,
108+ hue = " smoker" , style = " smoker" , size = " size" ,
109+ )
110+ fig = my_plot.get_figure()
111+ fig.savefig(" out.png" )
125112```
126113
114+ - Run the script
115+ - Check that the figure is created
116+
127117## External links
128118
129119- [ Python Data Science Handbook] ( https://jakevdp.github.io/PythonDataScienceHandbook/ )
0 commit comments