Assalam wbt. Jumpa lagi.
Post ke-11 yang lalu kita telah belajar bagaimana untuk setting banyak plot dalam satu frame. Post kali ini kita akan cuba untuk plot beberapa carta bar seperti yang dibincangkan di post ke-10 menggunakan data2.dat.
### copy script from here #######
import matplotlib.pyplot as plt
import numpy as np
fname='data2.dat'
data1=np.loadtxt(fname,skiprows=1)
data1[data1<0.0]=0.0
data1[data1==0.01]=0.0
data1[np.isnan(data1)]=0.0
station1=data1[:,0]
station1=station1.astype(int)
lat1=data1[:,1]
lon1=data1[:,2]
rain1=data1[:,3]
rain2=data1[:,4]
rain3=data1[:,5]
N = 17 ## total bar
ind = np.arange(N)
width = 0.95 # the width of the bars
color1='red'
color2='blue'
color3='green'
## SETTING PLOT AREA 3 IMAGES IN (1x3) ###
fig = plt.figure(figsize=(11,5))
plt.subplot(1,3,1)
plt.bar(ind, rain1, width, color=color1, tick_label = station1,
edgecolor="black",linewidth=0.5)
plt.xticks(rotation=90)
plt.xlabel('Meteorological Stations')
plt.ylabel('Hourly Rainfall (mm)')
plt.title('Rain 1')
plt.subplot(1,3,2)
plt.bar(ind, rain2, width, color=color2, tick_label = station1,
edgecolor="black",linewidth=0.5)
plt.xticks(rotation=90)
plt.xlabel('Meteorological Stations')
plt.ylabel('Hourly Rainfall (mm)')
plt.title('Rain 2')
plt.subplot(1,3,3)
plt.bar(ind, rain3, width, color=color3, tick_label = station1,
edgecolor="black",linewidth=0.5)
plt.xticks(rotation=90)
plt.xlabel('Meteorological Stations')
plt.ylabel('Hourly Rainfall(mm)')
plt.title('Rain 3')
#################AUTO FILE NAMING######################
import inspect
frame = inspect.currentframe()
path = inspect.getfile(frame)
fname = path.split('.')[0]
plt.savefig(fname + ".jpg",dpi=280,bbox_inches='tight')
#######################################################
plt.show()
### end copy script here ##
Paparan Imej:
Selamat mencuba!
No comments:
Post a Comment