Advanced Plotting

Quick Plotting

Line Plots

Simple plotting commands to look at data quickly

https://www.color-hex.com

https://matplotlib.org/stable/gallery/lines_bars_and_markers/linestyles.html

fig22.png

Bar Chart

Changing the style of the plot

Figure size

Axis labels

Font size of the axes labeles

Title

Font size of the title

Legend

Fontsize of the legend

Position of the legend

Multiple curves on same plot

Z order which means the order of the curves on top of each other

$x$ and $y$ limits

Histograms

Quick Histogram

Changing the number of bins

Normalization the area under the curve to unity

Differnt style of bins (useful for plotting multiple histograms)

Multiple subplots on 1 figure

Conveniently adding text to plots

Creating animations

Single Axes in one Figure

Adding Legend

Adding Title

ax.text(0.1, 0.1, "Text")

ax.text(0.1, 0.1, "Text", transform=ax.transAxes)

Title of all the plots

ax.tick_params(axis="both", labelsize=10)

Making x-ticks smaller

Example

Creating the following plot

Good habit to come up with complicated strings beforehand

2D Plots

Generate some data

Filled-in contour plots

More dense by levels

Contour Plot

3D Surface Plot

3D Surface Plot (Generally not preferred). However, they tend to work well in animations (we'll get to this later)

StreamPlots

For plotting vector fields

Image Reading

Plot image

Animations

Animations require relating the time of your problem to the frame of the animation, then specifying the frames per second

Create animation

Creating an empty text line

Creating an empty time line

Creating initial limit of the animation

Defining an animation function

Animating the figure by calling the animation function

Saving the animated figure as a gif file

The animation function can be used in other ways too. One can create 3D rotating gifs of surfaces.

Table of Contents and Notebook Setup

Advanced Subplot Features

Subplots of Unequal Scale

Sometimes we might have a figure composed of multiple plots but we don't want them to all be the same size (perhaps we have a main one and something else on the side). The following is a simple solution.

The 'gridspec_kw' argument is simple. Notie that we pass in an array of length three; this is the number of columns in the plot grid. This allows us to determine the ratio of the width of the columns. The same thing can be accomplished with the rows.

Subplots of Different Shape (and Management of Space)

Sometimes we want might two small subplots on the top and one small one on the bottom. This can be accomplished simply as follows.

The numerical arguments work as follows. The first two numbers 22 or 12 represent a 2x2 or 1x2 grid. The third number 1 or 3 or 2 represents the position in that grid that the plot should go.

Another way of accomplishing this is using the subplot2grid feature.

The first tuple breaks the figure apart into a 3x3 grid. The second tuple places the top left corner of the 'ax' in that location on the grid. The colspan and rowspan then stretch out the plot so that it covers more area of the grid.