Skip to content

Commit

Permalink
Add question numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
nf679 committed Nov 7, 2024
1 parent 70ac62b commit 70e9cb2
Showing 1 changed file with 17 additions and 17 deletions.
34 changes: 17 additions & 17 deletions python-data/solutions/ex05_matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
"id": "6bc7192f-0962-4168-b6c6-5fd44daa24b2",
"metadata": {},
"source": [
"1. Let's create some sample data to plot. Create an array called `xaxis` with the value `[1,2,3,4,5]` and an array called `yaxis` with the value `[2, 16, 4, 8, 7]`. Plot this data on a single axes. Don't forget to import matplotlib!"
"Q1. Let's create some sample data to plot. Create an array called `xaxis` with the value `[1,2,3,4,5]` and an array called `yaxis` with the value `[2, 16, 4, 8, 7]`. Plot this data on a single axes. Don't forget to import matplotlib!"
]
},
{
Expand Down Expand Up @@ -109,7 +109,7 @@
"id": "9cfacc0a-5af7-4912-b79e-0ac0743e20e5",
"metadata": {},
"source": [
"2. Create 6 empty plots in a 2x3 grid."
"Q2. Create 6 empty plots in a 2x3 grid."
]
},
{
Expand Down Expand Up @@ -170,7 +170,7 @@
"id": "97d9019c-750c-4a23-b023-2c9ed472f154",
"metadata": {},
"source": [
"3. Some inputs won't work as intended. Create a pandas dataframe as follows: \n",
"Q3. Some inputs won't work as intended. Create a pandas dataframe as follows: \n",
"\n",
"```\n",
"df = pd.DataFrame({\n",
Expand Down Expand Up @@ -258,7 +258,7 @@
"id": "8d0a5420-bd47-4771-aebb-125ab192f458",
"metadata": {},
"source": [
"4. We need to extract only the numeric values to plot. Let's extract them as a numpy array and try again. Use `np.asarray(df[['A', 'B']])` to create a numpy array from the numeric data. Try plotting it now."
"Q4. We need to extract only the numeric values to plot. Let's extract them as a numpy array and try again. Use `np.asarray(df[['A', 'B']])` to create a numpy array from the numeric data. Try plotting it now."
]
},
{
Expand Down Expand Up @@ -316,7 +316,7 @@
"id": "43bcbb06-d568-4091-a7a3-1e6ab4db0358",
"metadata": {},
"source": [
"5. Let's unpack the example given in the tutorial of using matplotlib with string-indexable objects. Instead of passing numpy arrays directly, we'll pass the names of the variables as strings.\n",
"Q5. Let's unpack the example given in the tutorial of using matplotlib with string-indexable objects. Instead of passing numpy arrays directly, we'll pass the names of the variables as strings.\n",
"\n",
"- Let's start by creating the dictionary. Create a variable called data using the following: \n",
" ```\n",
Expand Down Expand Up @@ -398,7 +398,7 @@
"id": "ce3d4439-773f-4a61-8556-9967942f7300",
"metadata": {},
"source": [
"6. So far, we've been creating plots in the object oriented way: explicitly creating figures and axes. The pyplot-style is very subtly different - we just don't need to create the axis or subplots.\n",
"Q6. So far, we've been creating plots in the object oriented way: explicitly creating figures and axes. The pyplot-style is very subtly different - we just don't need to create the axis or subplots.\n",
"- Create x axis data using `np.linspace(min, max, num)`. Create 10 values between 0 and 10.\n",
"- Create y axis data using `np.linspace` to create 10 values between 0 and 100.\n",
"- Plot this data on the implicit axes using `plt.plot()` - don't worry about seeting the figsize and layout."
Expand Down Expand Up @@ -464,7 +464,7 @@
"id": "1d18ed69-464a-4f6f-af12-4b43de5fb010",
"metadata": {},
"source": [
"7. Let's use the x and y values from before and create some new y values to practice styling plots.\n",
"Q7. Let's use the x and y values from before and create some new y values to practice styling plots.\n",
"- Create `y2 = np.linspace(0, -100, 10)`.\n",
"- Plot both of these sets of data on the same axes using the [Styling Artists example](https://matplotlib.org/stable/users/explain/quick_start.html#styling-artists).\n",
"- Plot the original y data in purple with the `--` linestyle and the new y data in green with the `:` linestyle.\n",
Expand Down Expand Up @@ -525,7 +525,7 @@
"id": "d3bba7b2-208b-4927-a246-b1ff18cadbf9",
"metadata": {},
"source": [
"8. There are lots of different customisation options in matplotlib for colour! You can even have different colours for the markers and outlines in a scatter plot. Use the following to generate some data for a scatter plot:\n",
"Q8. There are lots of different customisation options in matplotlib for colour! You can even have different colours for the markers and outlines in a scatter plot. Use the following to generate some data for a scatter plot:\n",
"```\n",
"data1, data2 = np.random.randn(2,100)\n",
"```\n",
Expand Down Expand Up @@ -584,7 +584,7 @@
"id": "e1308dc3-fc3c-4a49-a762-3fdb0a54eff4",
"metadata": {},
"source": [
"9. Generate two more scatter plot datasets as we did above then plot all 4 on one graph. Give each dataset a label and a different marker style - e.g. stars (`*`), plus (`P`) or diamonds (`D`). You can see more options for markers [in the documentation](https://matplotlib.org/stable/gallery/lines_bars_and_markers/marker_reference.html)."
"Q9. Generate two more scatter plot datasets as we did above then plot all 4 on one graph. Give each dataset a label and a different marker style - e.g. stars (`*`), plus (`P`) or diamonds (`D`). You can see more options for markers [in the documentation](https://matplotlib.org/stable/gallery/lines_bars_and_markers/marker_reference.html)."
]
},
{
Expand Down Expand Up @@ -652,7 +652,7 @@
"id": "a912305e-861a-428b-8223-9d245004baf7",
"metadata": {},
"source": [
"10. Take the plot we just created in the previous question and give it `xlabel`, `ylabel` and a `title` of your choice. Add some text to the plot saying `some text` at `50, 0`. Add an annotation at top saying `some annotation` with a black arrow pointing to some data using `xy=(40,2)` and `xytext=(3,1.5)`. Also add a legend identifying each data set."
"Q10. Take the plot we just created in the previous question and give it `xlabel`, `ylabel` and a `title` of your choice. Add some text to the plot saying `some text` at `50, 0`. Add an annotation at top saying `some annotation` with a black arrow pointing to some data using `xy=(40,2)` and `xytext=(3,1.5)`. Also add a legend identifying each data set."
]
},
{
Expand Down Expand Up @@ -726,7 +726,7 @@
"id": "27c4fc57-9ca3-442b-a62b-469a5f7d73c5",
"metadata": {},
"source": [
"11. Let's practice plotting some log scale data.\n",
"Q11. Let's practice plotting some log scale data.\n",
"- Create the xdata using `xdata = np.arange(5)`.\n",
"- Create the ydata using `ydata = np.array([0.1, 0.5, 1, 5, 10])`.\n",
"- Transform the y data by raising it to the power of 10 using `ydata = 10**ydata`.\n",
Expand Down Expand Up @@ -792,7 +792,7 @@
"id": "447fc1f2-81e1-4034-bbcb-b00d57ab88b3",
"metadata": {},
"source": [
"12. To demonstrate the difference between automatic and manual ticks, let's create two subplots. Follow the following steps:\n",
"Q12. To demonstrate the difference between automatic and manual ticks, let's create two subplots. Follow the following steps:\n",
"\n",
"- Create some data using `xdata = np.linspace(0, 99, 100)`, and `ydata = np.sin(xdata / 10)`\n",
"- Create a figure with 2 subplots arranged vertically.\n",
Expand Down Expand Up @@ -866,7 +866,7 @@
"id": "ecc8e915-c9ad-44a3-9964-2d047516a3bb",
"metadata": {},
"source": [
"13. Let's see how matplotlib handles plotting dates. We'll create a time series plot using an array of dates and random cumulative data:\n",
"Q13. Let's see how matplotlib handles plotting dates. We'll create a time series plot using an array of dates and random cumulative data:\n",
"- Generate a numpy array of dates starting from `2022-01-01` to `2022-01-10` at intervals of 3 hours using `dates=np.arange(np.datetime64('2022-01-01'), np.datetime64('2022-01-10'), np.timedelta64(3, 'h'))`\n",
"- Creative a cumulative sum of random numbers for the same length of the array of dates using `data=np.cumsum(np.random.randn(len(dates)))`\n",
"- Plot the data with the dates on the x axis and `data` on the y axis.\n",
Expand Down Expand Up @@ -929,7 +929,7 @@
"id": "0f022a40-f65d-4649-a63e-bcdbd4cdf4a1",
"metadata": {},
"source": [
"14. Let's have a go at plotting some categorical data. We'll create a bar chart using a list of categories and random values:\n",
"Q14. Let's have a go at plotting some categorical data. We'll create a bar chart using a list of categories and random values:\n",
"- Define a list of four fruit names `['apple', 'banana', 'cherry', 'date']`\n",
"- Generate random data for these categories using `np.random.rand()`\n",
"- Create a bar plot using these categories and their corresponding random values using `ax.bar()`"
Expand Down Expand Up @@ -993,7 +993,7 @@
"id": "9d86f4d0-fd73-40b4-aa36-beb40ffbab10",
"metadata": {},
"source": [
"15. Let's create a plot that demonstrates the use of both a secondary y-axis and a secondary x-axis with different scales:\n",
"Q15. Let's create a plot that demonstrates the use of both a secondary y-axis and a secondary x-axis with different scales:\n",
"- Generate a time series `t` ranging from 0 to 2π with 100 points (hint: use `np.linspace` with `np.pi`)\n",
"- Create two datasets: `s` for a sine wave and `l` for a linearly increasing dataset between 0 and the length of `t` (hint: use `np.sin()` and `np.arange()` with `len(t)`)\n",
"- Plot both datasets on the same figure\n",
Expand Down Expand Up @@ -1083,7 +1083,7 @@
"id": "4a4d9f48-0dbc-4b5e-a54a-f440c6c9f46b",
"metadata": {},
"source": [
"16. Let's create a series of suplots to practice visualizing data with colormaps:\n",
"Q16. Let's create a series of suplots to practice visualizing data with colormaps:\n",
"- Generate x and y data using `x, y = np.meshgrid(np.linspace(-3, 3, 128), np.linspace(-3, 3, 128))`\n",
"- Generate Z data using `z = (1 - x/2 + x**5 + y**3) * np.exp(-x**2 - y**2)`\n",
"- Generate 2 datsets to use for our scatter plot using `np.random.randn(100)` and generate a third dataset to use for the colors using `np.random.rand(100)`\n",
Expand Down Expand Up @@ -1189,7 +1189,7 @@
"id": "4d431ef9-295d-4c21-b9ef-2f4b118b11c6",
"metadata": {},
"source": [
"17. Let's create a figure with multiple subplots using the `suplot_mosiac` method. Each subplot should have its own distinct data and be customized with titles, labels, and a legend. You will also need to manipulate different axes in a single figure and work with multiple figures in a single program:\n",
"Q17. Let's create a figure with multiple subplots using the `suplot_mosiac` method. Each subplot should have its own distinct data and be customized with titles, labels, and a legend. You will also need to manipulate different axes in a single figure and work with multiple figures in a single program:\n",
"- Create data for the plots using:\n",
" ```\n",
" x = np.linspace(0,2 * np.pi, 100)\n",
Expand Down

0 comments on commit 70e9cb2

Please sign in to comment.