Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/workshops/matplotlib/animations.md
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,5 @@ os.system('rm ffmpeg*.png')
There are ways that you could optimize these plots further, such as not appending to an array, and instead allocating the whole array in memory, then change each individual step. Another thing you could do is generate the plot inside the data generation loop. However, because it is a random walk, we do not know before hand what x- and y-limits should be put, so we generate the data and then the plots.

In the next section we will talk about the Envision Center, RCAC's center for advanced visualization:

[Next Section](env_cent.md){ .md-button .md-button--primary }
2 changes: 1 addition & 1 deletion docs/workshops/matplotlib/plot_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ What if we want to plot a heat map? There are two main ways to do so:
- Imshow
- Pcolormesh

Imshow is much faster than Pcolormesh, but it also has more limitations. Imshow treats every data point like a pixel, and each pixel is the same size; it assumes a uniform, regular grid of points as an input. In the following script, we use a new NumPy function: `np.meshgrid()`. It takes at least two 1D NumPy arrays (vectors) and creates N, N-D matrix of points that correspond to the input vectors. In this case, we want to generate two matrices that correspond to the x- and y-directions. So, if we had two vectors: `[1,2]` (x) and `[3,4]` (y), and we called `np.meshgrid(x,y)` on them, it would give us two matrices as output:
Imshow is much faster than Pcolormesh, but it also has more limitations. Imshow treats every data point like a pixel, and each pixel is the same size; it assumes a uniform, regular grid of points as an input. In the following script, we use a new NumPy function: `np.meshgrid()`. It takes at least two 1D NumPy arrays (vectors) and creates N, N-Dimensional matrices of points that correspond to the input vectors. In this case, we want to generate two matrices that correspond to the x- and y-directions. So, if we had two vectors: `[1,2]` (x) and `[3,4]` (y), and we called `np.meshgrid(x,y)` on them, it would give us two matrices as output:

<table>
<caption>X</caption>
Expand Down
5 changes: 3 additions & 2 deletions docs/workshops/matplotlib/sine_plot.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ ax.plot(x_values,y_values,marker='*')

![An image showing a plotting frame, which contains a rather jagged version of a sine function, but now with stars at the points that are used to plot the lines.](/assets/images/workshops/matplotlib/Sin_star_plot.png "Sine Plot with Stars")

What can we do to improve the smoothness of the plot? The way to do this is to increase the number of points plotted. Right now, we are just plotting the integers from 0 to 9, but we want to plot some points in between. We could manually add points to a list for the x-values, but there is a better way: using NumPy's `linspace` function. It generates a NumPy array (which is easier to manipulate with math functions than a list), with three imputs to the function. They are, in order, the starting number, the ending number, and the number of points to make up the range. Modify the `x_values` assignment to use the NumPy `linspace` function like so:
What can we do to improve the smoothness of the plot? The way to do this is to increase the number of points plotted. Right now, we are just plotting the integers from 0 to 9, but we want to plot some points in between. We could manually add points to a list for the x-values, but there is a better way: using NumPy's `linspace` function. It generates a NumPy array (which is easier to manipulate with math functions than a list), with three inputs to the function. They are, in order, the starting number, the ending number, and the number of points to make up the range. Modify the `x_values` assignment to use the NumPy `linspace` function like so:
```python
x_values = np.linspace(0,10,100)
```
This makes a list between 0 and 10 with 100 points along the way. Now, we can simplify the `y_values` assignment because the x_values is now a NumPy array:
This makes a list between 0 and 10 with 100 points along the way. Now, we can simplify the `y_values` assignment because the `x_values` is now a NumPy array:
```python
y_values = np.sin(x_values)
```
Expand Down Expand Up @@ -182,4 +182,5 @@ We should get a plot that looks like this:
Notice that now the plot is no longer square, as the aspect ratio and the plot limits have dictated that the plot is longer in the x-direction than it is in the y-direction.

In the next section we will talk about some more advanced plotting topics, such as line styling and multiple lines:

[Next Section](adv_plots.md){ .md-button .md-button--primary }
Loading