# matplotlib geostrophic wind plot

I am working on an assignment that is teaching how to plot and label using matplotlib using Python. Science or math is not my background. I have been given the formula for calculating the geostrophic wind and we are to plot it (on the y-axis) versus the latitude on the x-axis.

I know how to plot give an x and a y. Beyond that, the formula is not making sense to me given my lack of background in the area.

Furthermore, there is a key to translate the symbols to the correct python code, but I don't know the English names to the symbols, making it very difficult.

For example, I am given

r'$x^{10}$'
r'$R_^{final}$'
r'$alpha^{\eta}$'


The first two are superscript and subscript. That I understand. But how this helps with the formula calculations I do not know.

I am given the values to put into the formula as well. An explanation of the order of operations would help. If, g0=9.81 ms-­‐2; ΔZ=60m; Δn=2x10^5m; and f=2Ωsin(φ)

My question is how do I put the values into the formula and then plot them in matplotlib? is it as easy as x and y?

Your answer was incorrect because the axes were flipped and it didn't plot the entire line.

This was the correct answer I was looking for.

import matplotlib.pyplot as plt
import numpy as np

# define the parameters
g = -9.81 # m/s^2
dZ = 60 # m
dx = 2e5 # m
phi = np.linspace(10,90) # deg
f = 2 * omega * np.sin(np.radians(phi)) # coriolis frequency, s^-1

# compute geostrophic wind, x-component
u_g = -1. * g/f * dZ/dx

# plot phi vs V_g
fig, ax = plt.subplots()
ax.plot(phi, u_g, color='#FF33CC')
ax.set_xlabel('$\phi$')
ax.set_ylabel('$V_{g}$ (m $s^-1$)')
plt.title('Geostrophic Wind vs. Latitude')
plt.show()


Let me start with: I don't know how appropriate this is for Data Science StackExchange. But I can't comment yet and think I can provide an answer, so here goes.

Putting the values into the formula. The quantities are:

• $g_0$: Standard gravity (9.81 m/s2);
• $\Delta Z$: Change in geopotential height over some distance;
• $\Delta n$: The distance over which you calculated $\Delta Z$; and
• $f$: The Coriolis parameter, measuring the rate of revolution at
• $\phi$: The chosen latitude.

You wrote the equation that links the Coriolis parameter $f$ to the latitude and to $\Omega=7.29\times 10^{-5}$ s$^{-1}$. Let's calculate this part first. I'm assuming that a) you can use numpy along with matplotlib, and b) you were asked to plot the geostrophic wind as a function of latitude. One way to enter this into Python is by writing:

> import numpy as np
> phi = np.arange(10, 91)
> Omega = 7.29e-5
> coriolis = 2 * Omega * np.sin(phi * np.pi/180)


The second line gives you a numpy array of latitudes, in degrees, from 10N to 90N. I left out the tropics, since $f=0$ at the equator; the geostrophic wind isn't well-defined there. The third line defines Omega, and the last line gives you a numpy array of values for $f$. Note that the argument of np.sin should be in radians, not degrees.

After doing this, the rest of the values are easy to input. For the order of operations, make sure everything in the numerator is grouped together and same for the denominator. You get:

> grav, dz, dn = 9.81, 60.0, 2.0e5
> VGeo = (grav * dz) / (coriolis * dn)


The first line uses a sequence of values to set grav ($g_0$), dz, and dn. The second line defines a numpy array for $V_g$, with the numerator and denominator grouped.

Plotting out the result. I don't know how familiar you are with the workings of matplotlib. Let me know if this doesn't make sense and I can expand on it. Many plots of something that varies in latitude have latitude on the y-axis, since that's the way globes and maps are oriented. So, when you make a plot of $(x,y)$ values, $y$ should be $\phi$ and $x$ should be $V_g$. A working example with some labels, using pyplot, might be:

> import matplotlib.pyplot as plt
> fig, ax = plt.subplots()
> ax.set_ylim(0,90)
> ax.set_xlim(0,125)
> ax.plot(VGeo, phi, linestyle='-', color='k')
> ax.set_ylabel('Latitude $\phi$')
> ax.set_xlabel('Wind $V_g$')
> ax.set_title('Geostrophic wind $V_g = \frac{g_0 \Delta z}{f \Delta n}$')
> fig.savefig('test.png', format='png')


I'm doing several things here. The second line creates a figure and axes using plt.subplots(); without any arguments, this returns a single axis. Next, I'm setting the x- and y-limits so that we see all the data and so that the y-axis starts at the equator (even though we don't plot values south of 10N, I think it looks better). Then I'm just plotting $(x,y)=(V_g,\phi)$, with a solid black line. The next three lines involve creating labels using TeX formatting. The last line is saving the figure to a local PNG file.

Let me know how it works out!