-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprecip_by_litho_box_new.py
137 lines (89 loc) · 4.27 KB
/
precip_by_litho_box_new.py
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#Ksn by elevation
import matplotlib
matplotlib.use("Agg")
from matplotlib import pyplot as plt
import pandas as pd
import sys
import numpy as np
from numpy import median
import matplotlib.cm as cm
import matplotlib.patches as mpatches
from mpl_toolkits.axes_grid.inset_locator import inset_axes
target = '/exports/csce/datastore/geos/users/s1134744/LSDTopoTools/Topographic_projects/full_himalaya_5000/'
source= '0_4_ex_MChiSegmented_burned_outlier_removed.csv'
def getAxisHist(column):
with open(target+source,'r') as csvfile:
df = pd.read_csv(csvfile,delimiter=',')
x_list = df[column].tolist()
y_list = df['secondary_burned_data'].tolist()
return x_list,y_list
litho_mins = [30000,50000,90000,100000,110000]
litho_maxs = [40000,60000,100000,1110000,120000]
titles = ["Metamorphics","Acid Plutonic Rocks","Carbonate Sedimentary Rocks",
"Mixed Sedimentary Rocks","Siliciclastic Sedimentary Rocks"]
names_c = [str(x)+'-'+str(y) for x,y in zip(range(0,6000,500),range(500,6500,500))]
location_list = [151,152,153,154,155]
def getAxisBox(column,mins,maxs):
x_list = []
x_ticks = []
with open(target+source,'r') as csvfile:
df = pd.read_csv(csvfile,delimiter=',')
df_A = df[df['m_chi'] > 0]
for x,y in zip(litho_mins,litho_maxs):
selectedDF_a = df_A[df_A['burned_dat'] >= x]
selectedDF_a = selectedDF_a[selectedDF_a['burned_dat'] < y]
x_list_b = []
x_tick_b = []
for lower,upper in zip(mins,maxs):
selectedDF = selectedDF_a[selectedDF_a[column] >= lower]
selectedDF = selectedDF[selectedDF[column] < upper]
series = selectedDF['m_chi']
print selectedDF
lister = series.tolist()
data_count = len(lister)
x_list_b.append(lister)
x_tick_b.append(data_count)
x_ticks.append(x_tick_b)
x_list.append(x_list_b)
return x_list,x_ticks
fig = plt.figure(1, figsize=(22,10))
x_list,x_ticks = getAxisBox('secondary_',range(0,6000,500),range(500,6500,500))
#print x_list
ax = fig.add_subplot(location_list[0])
new_names = ['n:'+str(x) for x in x_ticks[0]]
box = ax.boxplot(x_list[0],labels=new_names,patch_artist=True,medianprops=dict(linestyle='-', linewidth=2.5, color='k'))
x = np.arange(len(range(0,6000,500)))
ys = [i+x+(i*x)**2 for i in range(len(range(0,6000,500)))]
colours = cm.Blues(np.linspace(0, 1, len(ys)))
for patch, color in zip(box['boxes'], colours):
patch.set_facecolor(color)
ax.set_xticklabels(new_names,rotation=90)
#plt.rc('xaxis', labelsize=20)
plt.ylim(ymin=0,ymax=250)
plt.ylabel(r"$K_{sn}$",fontsize=18)
#plt.xlabel("Lithology")
#ax.axes.get_xaxis().set_visible(False)
plt.title(titles[0],fontsize=14)
for box,tick,location,name in zip(x_list[1:],x_ticks[1:],location_list[1:],titles[1:]):
#print box
ax = fig.add_subplot(location)
names = [str(x)+'\n'+str(y) for x,y in zip(range(0,6000,500),range(500,6500,500))]
new_names = ['n:'+str(x) for x in tick]
box = ax.boxplot(box,labels=new_names,patch_artist=True,medianprops=dict(linestyle='-', linewidth=2.5, color='k'))
for patch, color in zip(box['boxes'], colours):
patch.set_facecolor(color)
ax.set_xticklabels(new_names,rotation=90)
ax.set_yticklabels([])
#plt.rc('xaxis', labelsize=20)
plt.ylim(ymin=0,ymax=250)
#plt.ylabel("Ksn")
#plt.xlabel("Precipitation in 500 mm/year bins")
plt.title(name,fontsize=14)
plt.subplots_adjust(wspace=0, hspace=0,bottom=0.13)
#fig.tight_layout()
legends = []
for colour,name in zip(colours,names_c):
legend = mpatches.Patch(edgecolor='k',facecolor=colour, label=name)
legends.append(legend)
leg = fig.legend(legends, names_c,'lower center',ncol=12,title=r'Precipitation ($mm\,yr^{-1}$)')
fig.savefig('../precip_by_litho_0.4_removed.png', bbox_inches='tight')