Difference between revisions of "EGR 103/Spring 2021/Lab 6"
(Created page with "<div class="noautonum">__TOC__</div> == Errors / Additions == None yet! == 6.1 Introduction == There are several different types of problem to work on this week. The ones i...") |
(→6.4.3 Chapra 3.26) |
||
Line 33: | Line 33: | ||
=== 6.4.3 Chapra 3.26 === | === 6.4.3 Chapra 3.26 === | ||
+ | '''Important''': If your computer is struggling to get 10000 dots to work, you can reduce this to 1000! | ||
+ | |||
When you plot $$n$$ vs. $$m$$, use the format specifier '.' to plot dots. You will get 10000 slate blue dots since that is the default color for the first series plotted. You can also make each dot its own color by plotting it individually and using the <code>color</code> kwarg. This keyword argument expects either a nickname or a tuple of three numbers. The numbers need to be between 0 and 1 and will indicate how much red, green, and blue to use. As an example, agents could either use <code>color='m'</code> or <code>color=(1, 0, 1)</code>. Here is a sample code that generates 1000 normally distributed random 2D locations, plots them all as blue dots first, then plots them going from black on the top to bright green on the bottom: | When you plot $$n$$ vs. $$m$$, use the format specifier '.' to plot dots. You will get 10000 slate blue dots since that is the default color for the first series plotted. You can also make each dot its own color by plotting it individually and using the <code>color</code> kwarg. This keyword argument expects either a nickname or a tuple of three numbers. The numbers need to be between 0 and 1 and will indicate how much red, green, and blue to use. As an example, agents could either use <code>color='m'</code> or <code>color=(1, 0, 1)</code>. Here is a sample code that generates 1000 normally distributed random 2D locations, plots them all as blue dots first, then plots them going from black on the top to bright green on the bottom: | ||
<syntaxhighlight lang=python> | <syntaxhighlight lang=python> |
Revision as of 00:03, 3 March 2021
Errors / Additions
None yet!
6.1 Introduction
There are several different types of problem to work on this week. The ones in lab each have plots associated with them.
6.2 Getting Started
6.3 APT
The third APT assignment is active. The APT page has some hints for how to solve problems. One quick note: a set is a collection of elements where each element is unique. If you cast some other collection (for example, a list or a string) as a set, the recast version will have as many elements as the number of unique entries in the original.
In [1]: set([1, 2, 3, 4, 5, 2, 4, 2])
Out[1]: {1, 2, 3, 4, 5}
In [2]: set("hello")
Out[2]: {'e', 'h', 'l', 'o'}
6.4 Individual Lab Assignment
6.4.1 Chapra 2.26
See the Python:Plotting/Subplots page for how to get a single solumn of plots with a shared $$x$$ axis. Also, use:
fig.set_size_inches(6, 8, forward=True)
just after you create the figure to make it 6" wide and 8" tall.
6.4.2 Chapra 2.27
See the Python:Plotting/Subplots page for how to get two rows of two columns of plots. If you use the subplots method to make a 2x2 array, see Python:Plotting#Example for how to remove unused axes.
6.4.3 Chapra 3.26
Important: If your computer is struggling to get 10000 dots to work, you can reduce this to 1000!
When you plot $$n$$ vs. $$m$$, use the format specifier '.' to plot dots. You will get 10000 slate blue dots since that is the default color for the first series plotted. You can also make each dot its own color by plotting it individually and using the color
kwarg. This keyword argument expects either a nickname or a tuple of three numbers. The numbers need to be between 0 and 1 and will indicate how much red, green, and blue to use. As an example, agents could either use color='m'
or color=(1, 0, 1)
. Here is a sample code that generates 1000 normally distributed random 2D locations, plots them all as blue dots first, then plots them going from black on the top to bright green on the bottom:
import numpy as np
import matplotlib.pyplot as plt
def scaled(val, minval, maxval):
return (val-minval)/(maxval-minval)
x = np.random.normal(0, 1, 1000)
y = np.random.normal(0, 1, 1000)
fig, ax = plt.subplots(num=1, clear=True)
ax.plot(x, y, '.')
fig, ax = plt.subplots(num=2, clear=True)
for k in range(1000):
ax.plot(x[k], y[k], '.',
color=(0, scaled(y[k], y.min(), y.max()), 0))
You should make four plots:
- All the dots slate blue
- Dots range from black at the bottom to pure blue at the top
- Each dot is a total random color
- Your own mapping - you will need to describe the math and the color scheme in the lab report