Plotting NOAA data...

Hi all,

I am pretty new to matplotlib and I have a big issue... I am trying to plot
data from a grib file from noaa and I am not sure what's the best way to go
about it. Until now, I am extracting the data i need in CSV files but I am
not able to plot it. Here is a sample of the code that I am using:

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')
plt.contour(r.longitude, r.latitude)
plt.show()

Which errors out and requires a 2d array.

By the way, here is a data file: http://downloads.75ive.com/testdata.csv
http://downloads.75ive.com/testdata.csv

Any help is appreciated!

···


View this message in context: http://www.nabble.com/Plotting-NOAA-data…-tp21139727p21139727.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

Hi all,

I am pretty new to matplotlib and I have a big issue... I am trying to plot
data from a grib file from noaa and I am not sure what's the best way to go
about it. Until now, I am extracting the data i need in CSV files but I am
not able to plot it. Here is a sample of the code that I am using:

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')
plt.contour(r.longitude, r.latitude)
plt.show()

Which errors out and requires a 2d array.

By the way, here is a data file: http://downloads.75ive.com/testdata.csv
http://downloads.75ive.com/testdata.csv

Any help is appreciated!

I assume you meant to include your dependent variable in the call to contour, not just your longitude and latitude. In any case, you need to grid your data onto a 2D array. In the mpl examples, see griddata_demo.py.

Eric

2008/12/23 Eric Firing <efiring@...202...>:
antonv wrote:

Hi all,

I am trying to plot data from a grib file from noaa ...
Here is a sample of the code that I am using:

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')
plt.contour(r.longitude, r.latitude)
plt.show()

Which errors out and requires a 2d array.

By the way, here is a data file: http://downloads.75ive.com/testdata.csv
http://downloads.75ive.com/testdata.csv

Any help is appreciated!

I assume you meant to include your dependent variable in the call to
contour, not just your longitude and latitude. In any case, you need to
grid your data onto a 2D array. In the mpl examples, see griddata_demo.py.

If you just want a quick overview, you could also try

plt.scatter(r.longitude, r.latitude, c=r.dirpw_200812191800, s=5, edgecolors='none')
plt.colorbar()
plt.show()

Cheers,
Scott

Scott, the Scatter function works great but i am really looking to use the
contourf one.

Eric, you're right, the way I had it initially it was missing the z value. I
looked at the griddata example and here is the code I came up with:

from numpy.random import uniform, seed
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
import numpy as np

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')

x = r.longitude
y = r.latitude
z = r.dirpw_200812191800
xi = r.x
yi = r.y

# grid the data.
zi = griddata(x,y,z,xi,yi)

CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.jet)
plt.colorbar() # draw colorbar

plt.show()

Which still errors out: 'output grid defined by xi,yi must be monotone
increasing'
The xi and yi are from the first 2 columns of the csv file and I thought
they were monotonically increasing. What am I missing?

antonv wrote:

···

Hi all,

I am pretty new to matplotlib and I have a big issue... I am trying to
plot data from a grib file from noaa and I am not sure what's the best way
to go about it. Until now, I am extracting the data i need in CSV files
but I am not able to plot it. Here is a sample of the code that I am
using:

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')
plt.contour(r.longitude, r.latitude)
plt.show()

Which errors out and requires a 2d array.

By the way, here is a data file: http://downloads.75ive.com/testdata.csv
http://downloads.75ive.com/testdata.csv

Any help is appreciated!


View this message in context: http://www.nabble.com/Plotting-NOAA-data…-tp21139727p21147081.html
Sent from the matplotlib - users mailing list archive at Nabble.com.

antonv wrote:

Scott, the Scatter function works great but i am really looking to use the
contourf one.

Eric, you're right, the way I had it initially it was missing the z value. I
looked at the griddata example and here is the code I came up with:
  

Since you read your data from a GRIB file, it must be on a regular grid. Therefore, you don't need to use griddata to grid your data.

The best way to go would be to use PyNIO to read the grib data into a 2D array, and then plot it directly with contourf (perhaps using the Basemap toolkit if you want to display a map underneath).

If you point me to your GRIB file I can show you what I mean.

-Jeff

···

from numpy.random import uniform, seed
from matplotlib.mlab import griddata
import matplotlib.pyplot as plt
import numpy as np

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')

x = r.longitude
y = r.latitude
z = r.dirpw_200812191800
xi = r.x yi = r.y

# grid the data.
zi = griddata(x,y,z,xi,yi)

CS = plt.contourf(xi,yi,zi,15,cmap=plt.cm.jet)
plt.colorbar() # draw colorbar

plt.show()

Which still errors out: 'output grid defined by xi,yi must be monotone
increasing'
The xi and yi are from the first 2 columns of the csv file and I thought
they were monotonically increasing. What am I missing?

antonv wrote:
  

Hi all,

I am pretty new to matplotlib and I have a big issue... I am trying to
plot data from a grib file from noaa and I am not sure what's the best way
to go about it. Until now, I am extracting the data i need in CSV files
but I am not able to plot it. Here is a sample of the code that I am
using:

import matplotlib.pyplot as plt
import matplotlib.mlab as mlab

r =
mlab.csv2rec('D:/SocalScubaInfo/Data/Outputs/CSV_files/DIRPW_12191800.csv')
plt.contour(r.longitude, r.latitude)
plt.show()

Which errors out and requires a 2d array.

By the way, here is a data file: http://downloads.75ive.com/testdata.csv
http://downloads.75ive.com/testdata.csv

Any help is appreciated!