<jupyter_start><jupyter_text>Solutions to Lesson 6 ExercisesFor each exercise, the solutions below show one possible way of solving it, but you might have used a different approach, and that's great! There is almost always more than one way to solve any particular problem in Python. Initial Setup Since this notebook is in the `solutions` sub-folder, use the  magic command `%cd` to go up one folder to the main project folder to keep the file paths the same as in the lessons:<jupyter_code>%cd ..<jupyter_output>C:\Users\jenfl\Projects\eoas-python<jupyter_text>Import libraries, display plots inline, initialize variables from lesson:<jupyter_code>import pandas
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature

%matplotlib inline
world = pandas.read_csv('data/gapminder_world_data_2018.csv')
world['area'] = world['population'] / world['pop_density']
cities = pandas.read_csv('data/country_capitals.csv')<jupyter_output><empty_output><jupyter_text>Exercise 6.1**a)** First, create the following variables:```pythonx_data = [0, 1, 2, 3, 4, 5, 6]y_linear = [0, 2, 4, 6, 8, 10, 12]y_squares = [0, 1, 4, 9, 16, 25, 36]```Plot `y_linear` vs. `x_data` and `y_squares` vs. `x_data` on a figure with the following customizations:- Figure size 5" wide by 6" tall- `y_linear` vs. `x_data` as a line plot with line width of 2 and color `'purple'`- `y_squares` vs. `x_data` as a line plot with line width of 4, line style `'dotted'`, and color `'forestgreen'`- Figure title `'Straight Line and 2nd Order Polynomial'`<jupyter_code>x_data = [0, 1, 2, 3, 4, 5, 6]
y_linear = [0, 2, 4, 6, 8, 10, 12]
y_squares = [0, 1, 4, 9, 16, 25, 36]
fig, ax = plt.subplots(figsize=(5, 6))
ax.plot(x_data, y_linear, linewidth=2, color='purple')
ax.plot(x_data, y_squares, linewidth=4, linestyle='dotted', color='forestgreen')
ax.set_title('Straight Line and 2nd Order Polynomial');<jupyter_output><empty_output><jupyter_text>**b)** Save the figure in `.png` and `.pdf` formats<jupyter_code>fig.savefig('linear-and-polynomial.png', dpi=300)
fig.savefig('linear-and-polynomial.pdf')<jupyter_output><empty_output><jupyter_text>Bonus exercises**c)** Try out other customizations such as using other colors from the [named color list](https://matplotlib.org/examples/color/named_colors.html), different line styles, assigning x- and y-labels, changing the axis limits with `ax.set_xlim()` and `ax.set_ylim()`, splitting the figure into subplots with one above and one below (instead of side by side), and so on...<jupyter_code># One example
fig, ax_array = plt.subplots(2, 1, figsize=(4, 8))
ax1 = ax_array[0]
ax2 = ax_array[1]

ax1.plot(x_data, y_linear, linewidth=2, linestyle='dashed', color='maroon')
ax1.set_title('Linear')
ax1.set_xlim(0, 6.5)
ax1.set_ylim(0, 12.5)

ax2.plot(x_data, y_squares, linewidth=2, color='navy')
ax2.set_title('2nd Order Polynomial')
ax2.set_xlim(0, 6.5)
ax2.set_ylim(0, 40)

fig.tight_layout()<jupyter_output><empty_output><jupyter_text>Exercise 6.2**a)** Create a map with the following specifications:- 6" wide by 6" tall- `ccrs.Orthographic()` projection- Stock image background- Any other features or data you'd like to add<jupyter_code>fig = plt.figure(figsize=(6, 6))
ax = fig.add_subplot(1, 1, 1, projection=ccrs.Orthographic())
ax.stock_img()
ax.scatter(data=cities, x='Longitude', y='Latitude', marker='.', 
           color='black', transform=ccrs.PlateCarree());<jupyter_output><empty_output><jupyter_text>**b)** Try out different values of the `central_latitude` and `central_longitude` keyword arguments to `ccrs.Orthographic()` and see how the map changes.<jupyter_code>fig = plt.figure(figsize=(6, 6))
proj = ccrs.Orthographic(central_longitude=90)
ax = fig.add_subplot(1, 1, 1, projection=proj)
ax.stock_img()
ax.scatter(data=cities, x='Longitude', y='Latitude', marker='.', 
           color='black', transform=ccrs.PlateCarree());
fig = plt.figure(figsize=(6, 6))
proj = ccrs.Orthographic(central_longitude=90, central_latitude=60)
ax = fig.add_subplot(1, 1, 1, projection=proj)
ax.stock_img()
ax.scatter(data=cities, x='Longitude', y='Latitude', marker='.', 
           color='black', transform=ccrs.PlateCarree());<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup