Plotting dates on the y-axis of a contour map/ hovmoller

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Plotting dates on the y-axis of a contour map/ hovmoller

vaultron94
Hello all,

So I ran into a snare when making a Hovmoller for a case study. I have everything done and colors picked out. But for the life of me cannot find a way to get the Y-axis to plot the dates provided in the data. Here is the script I have.

import numpy as np
import datetime
import matplotlib.pyplot as plt
import os
import pandas as pd

def cmap(cmap):
    cmap = plt.cm.get_cmap(cmap)

data = pd.read_excel('/Users/operator/Documents/Hovmoller_dewpt.xlsx')

a=np.array(data)

time= (a[:,0])
lat= (a[:,1])
lon= (a[:,2])
BATA= (a[:,3])
BSPA= (a[:,4])
BUFF= (a[:,5])
CLIF= (a[:,6])
FAYE= (a[:,7])
HERK= (a[:,8])
JOHN= (a[:,9])
JORD= (a[:,10])
OPPE= (a[:,11])
WEST= (a[:,12])
timeZ= (a[:,13])


b=np.vstack((BUFF,BATA,CLIF,JORD,FAYE,WEST,HERK,OPPE,JOHN,BSPA)).T

plt.contourf(b, np.arange(40,67), cmap=('jet'))


plt.xlabel('BUFF  BATA  CLIF  JORD  FAYE  WEST  HERK  OPPE  JOHN  BSPA')
plt.ylabel('Time')
plt.grid('off')
plt.colorbar()

plt.title('Dewpoint Hovmoller for Mesonet Sites')
plt.figure()

#timeZ contains the dates I want, and instead of having the number of rows as the y axis I want the dates there instead. Attached is the graphic I get as of now. Any thoughts or advice is much appreciated!

Thank you

Reply | Threaded
Open this post in threaded view
|

Re: Plotting dates on the y-axis of a contour map/ hovmoller

Paul Hobson-2
The contour function can be called in many forms. 

Without your data, it's hard to see exactly what's going on, but it looks like you're using the contour(Z, V) form.

I recommend using the contour(X, Y, Z) form. Passing Y as an array of datetime-like object should "just work".

If it doesn't, boil this example down to something we can copy-paste into a terminal/notebook and mess around with. A 5 x 5 array for your Z values and some of the dates in the format you currently have them should suffice.
-Paul 

On Mon, Jul 10, 2017 at 12:26 PM, vaultron94 <[hidden email]> wrote:
Hello all,

So I ran into a snare when making a Hovmoller for a case study. I have
everything done and colors picked out. But for the life of me cannot find a
way to get the Y-axis to plot the dates provided in the data. Here is the
script I have.

import numpy as np
import datetime
import matplotlib.pyplot as plt
import os
import pandas as pd

def cmap(cmap):
    cmap = plt.cm.get_cmap(cmap)

data = pd.read_excel('/Users/operator/Documents/Hovmoller_dewpt.xlsx')

a=np.array(data)

time= (a[:,0])
lat= (a[:,1])
lon= (a[:,2])
BATA= (a[:,3])
BSPA= (a[:,4])
BUFF= (a[:,5])
CLIF= (a[:,6])
FAYE= (a[:,7])
HERK= (a[:,8])
JOHN= (a[:,9])
JORD= (a[:,10])
OPPE= (a[:,11])
WEST= (a[:,12])
timeZ= (a[:,13])


b=np.vstack((BUFF,BATA,CLIF,JORD,FAYE,WEST,HERK,OPPE,JOHN,BSPA)).T

plt.contourf(b, np.arange(40,67), cmap=('jet'))


plt.xlabel('BUFF  BATA  CLIF  JORD  FAYE  WEST  HERK  OPPE  JOHN  BSPA')
plt.ylabel('Time')
plt.grid('off')
plt.colorbar()

plt.title('Dewpoint Hovmoller for Mesonet Sites')
plt.figure()

#timeZ contains the dates I want, and instead of having the number of rows
as the y axis I want the dates there instead. Attached is the graphic I get
as of now. Any thoughts or advice is much appreciated!

Thank you

<http://matplotlib.1069221.n5.nabble.com/file/n48081/DewPoint.png>



--
View this message in context: http://matplotlib.1069221.n5.nabble.com/Plotting-dates-on-the-y-axis-of-a-contour-map-hovmoller-tp48081.html
Sent from the matplotlib - users mailing list archive at Nabble.com.
_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users


_______________________________________________
Matplotlib-users mailing list
[hidden email]
https://mail.python.org/mailman/listinfo/matplotlib-users