-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemp_plot.py
More file actions
55 lines (43 loc) · 1.66 KB
/
temp_plot.py
File metadata and controls
55 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
from mpl_toolkits.mplot3d import Axes3D
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import os.path
from os import path
import glob
from PIL import Image
DataFile = "argo_data.csv"
def Plot_temperature(data):
'''This function is to plot the ocean temperature for given coordinates through out the month'''
month = data["MONTH-YEAR"].unique()
for m in month:
temp_monthly = data.loc[data['MONTH-YEAR']==m]
month_name = m.replace(' ' , '_')
x = temp_monthly['LONGITUDE']
y = temp_monthly['LATITUDE']
z = temp_monthly['PRESURE (db)']
c = temp_monthly['TEMPERATURE (C)']
fig = plt.figure(figsize=(18,10))
ax = fig.add_subplot(111, projection='3d')
ax.set_xlabel("Longitude")
ax.set_ylabel("Latitude")
ax.set_zlabel("Depth(m)")
ax.invert_zaxis()
img = ax.scatter(x, y, z, c=c, cmap=plt.hot())
fig.colorbar(img, label='Temperature (*c)')
plt.title('Ocean Temperature plot for the month of %s' % month_name)
plt.savefig('oceanTemp_'+month_name+'.png')
print('oceanTemp_'+month_name+'.png '+"File created")
plt.close(fig)
if path.exists(DataFile):
data = pd.read_csv(DataFile)
Plot_temperature(data)
# Create a .gif file as final output
file_in = glob.glob("oceanTemp_*.png")
file_in.sort(key=os.path.getmtime) #sorting files by timestamp
file_out = "OceanTemp.gif"
img, *imgs = [Image.open(f) for f in file_in]
img.save(fp=file_out, format='GIF', append_images=imgs,
save_all=True, duration=1200, loop=0)
else:
print("The file Doesn't exist...!")