Assalamualaikum wbt dan jumpa lagi.
Post kali ini kita akan cuba untuk membuat analisa taburan suhu purata setiap data yang telah dibelakkan di dalam post ke 21 yang lalu. Selain itu kita akan cuba untuk aplikasi pengetahuan yang telah dipelajari sebelumnya iaitu, menggunakan library glob, library os, setting path dan open folders serta truncation bagi menetapkan nama baharu sesebuah fail atau plot yang di lakukan.
### copy script here ###
import numpy as np
import matplotlib.pyplot as plt
import os
import glob
plt.rcParams.update({'font.size':12,'font.family': 'serif'})
### searching current working folder
folder = os.getcwd()
path1=folder+'/Data/'
os.makedirs(os.path.dirname(path1), exist_ok=True)
import numpy as np
import matplotlib.pyplot as plt
import os
import glob
plt.rcParams.update({'font.size':12,'font.family': 'serif'})
### searching current working folder
folder = os.getcwd()
path1=folder+'/Data/'
os.makedirs(os.path.dirname(path1), exist_ok=True)
### open new folder for saving plot
path2=folder+'/Output-Histogram/'
os.makedirs(os.path.dirname(path2), exist_ok=True)
os.makedirs(os.path.dirname(path2), exist_ok=True)
### calling to open data using library glob
files=glob.glob(path1+'*.dat')
### setting plotting frame size
plt.figure(figsize = (8, 6))
ax = plt.subplot()
print(x)
output_name=x[-15:-9]
print(output_name)
data2=np.loadtxt(x)
lats=data2[:,0]
lons=data2[:,1]
temp=data2[:,2]
min_temp=min(temp)
max_temp=max(temp)
## setting temperature range domain here we set from 20 to 28
range = (20, 28) ## temperature range
ax = plt.subplot()
### using python LOOP to process all data
### applying truncation for deciding new names as discussed in post 21
for x in files:print(x)
output_name=x[-15:-9]
print(output_name)
data2=np.loadtxt(x)
lats=data2[:,0]
lons=data2[:,1]
temp=data2[:,2]
min_temp=min(temp)
max_temp=max(temp)
## setting temperature range domain here we set from 20 to 28
range = (20, 28) ## temperature range
## setting how many bars that we want to be plotted
bins = 40
bins = 40
## plotting command for a histogram with its parameters
plt.hist(temp, bins, range, color = 'red',
histtype = 'bar', rwidth = 0.8)
##set x-axis label as vertical
plt.xticks(rotation=90)
##set x-axis label as vertical
plt.xticks(rotation=90)
## naming the x-axis
plt.xlabel('Temperature (Degree Celcius)')
plt.xlabel('Temperature (Degree Celcius)')
## naming the y-axis
plt.ylabel('Frequency')
plt.ylabel('Frequency')
### applying map title
plt.title('Temperature Histogram in '+output_name)
## save plot or image onto file created above under path 2
plt.title('Temperature Histogram in '+output_name)
## save plot or image onto file created above under path 2
plt.savefig(path2+output_name+ ".png",dpi=280,
bbox_inches='tight')
plt.clf()
Contoh plot:
Thanks for sharing this information
ReplyDeletePython Online Training
Python Training
your welcome. im very sorry because no latest post shared lately. I will find my best time to write and share with you soon
ReplyDelete