-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfigure_10-b_script.py
368 lines (311 loc) · 18.2 KB
/
figure_10-b_script.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import matplotlib.pyplot as plt
import numpy as np
import matplotlib
import matplotlib.patches as mpatches
from matplotlib.ticker import MultipleLocator
import statsmodels.api as sm
plt.style.use("default") # set the plot style
plt.rcParams["font.family"] = "Times New Roman" # To globaly change the font POLICE
plt.rcParams["font.weight"] = "bold" # To write all font in bold
plt.rcParams["axes.labelweight"] = "bold" # To write all labels in bold
###############################################################################################################################
###########################################< Section n °1 : loading and plotting DATA >########################################
###############################################################################################################################
# loading the "to be used DATA"
data_1 = np.loadtxt("figure_10-b_NaNbO2F2_data.txt", skiprows = 1)
data_2 = np.loadtxt("figure_10-b_NaTaO2F2_data.txt", skiprows = 1)
# Defining figure area and plotting data with y-errorbars on each data point
# DATA n°1
f, axis = plt.subplots(3, 2, figsize=(8, 10), sharex=True)
axis[0, 0].errorbar(data_1[:, 0], data_1[:, 1], yerr = data_1[:, 2], fmt = 'o', linewidth = .8,
elinewidth = 1, ecolor = 'k', color = 'r', capsize = 4, ms = 5, mec = 'k')
axis[1, 0].errorbar(data_1[:, 0], data_1[:, 5], yerr = data_1[:, 6], fmt="o", linewidth = .8,
elinewidth = 1, ecolor='k', color = 'r', capsize = 4, ms = 5, mec = 'k')
axis[2, 0].errorbar(data_1[:, 0], data_1[:, 7], yerr = data_1[:, 8], fmt = "o", linewidth = .8,
elinewidth = 1, ecolor = 'k', color = 'r', capsize = 4, ms = 5, mec = 'k')
# DATA n°2
axis[0, 1].errorbar(data_2[:, 0], data_2[:, 1], yerr = data_2[:, 2], fmt = 'o', linewidth = .8,
elinewidth = 1, ecolor = 'k', color = 'c', capsize = 4, ms = 5, mec = 'k')
axis[1, 1].errorbar(data_2[:, 0], data_2[:, 5], yerr = data_2[:, 6], fmt = 'o', linewidth = .8,
elinewidth = 1, ecolor = 'k', color = 'c', capsize = 4, ms = 5, mec = 'k')
axis[2, 1].errorbar(data_2[:, 0], data_2[:, 7], yerr = data_2[:, 8], fmt = "o", linewidth = .8,
elinewidth = 1, ecolor = 'k', color = 'c', capsize = 4, ms = 5, mec = 'k')
# Setting axis twins
ax00 = axis[0, 0].twinx()
ax10 = axis[1, 0].twinx()
ax20 = axis[2, 0].twinx()
ax01 = axis[0, 1].twinx()
ax11 = axis[1, 1].twinx()
ax21 = axis[2, 1].twinx()
# Hiding ticklabels
ax00.axes.get_yaxis().set_ticklabels([])
ax10.axes.get_yaxis().set_ticklabels([])
ax20.axes.get_yaxis().set_ticklabels([])
ax01.axes.get_yaxis().set_ticklabels([])
ax11.axes.get_yaxis().set_ticklabels([])
ax21.axes.get_yaxis().set_ticklabels([])
# hiding the spines between the different plots of the twin axis
ax00.spines['bottom'].set_visible(False)
ax10.spines['top'].set_visible(False)
ax10.spines['bottom'].set_visible(False)
ax20.spines['top'].set_visible(False)
ax01.spines['bottom'].set_visible(False)
ax11.spines['top'].set_visible(False)
ax11.spines['bottom'].set_visible(False)
ax21.spines['top'].set_visible(False)
# Setting limites of the twin axis
# DATA n°1
ax00.set_ylim(52, 64)
ax10.set_ylim(102, 114)
ax20.set_ylim(126, 138)
# DATA n°2
ax01.set_ylim(60, 72)
ax11.set_ylim(94, 106)
ax21.set_ylim(110, 122)
# Managing major ticks of the twin axis
ax00.tick_params(top = False, labeltop = False, bottom = False, labelbottom = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
ax10.tick_params(top = False, labeltop = False, bottom = False, labelbottom = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
ax20.tick_params(top = False, labeltop = False, bottom = False, labelbottom = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
ax01.tick_params(left = True, labelleft = False, right = False, labelright = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
ax11.tick_params(left = True, labelleft = False, right = False, labelright = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
ax21.tick_params(left = True, labelleft = False, right = False, labelright = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
# Managing minor ticks of the twin axis
ax00.yaxis.set_minor_locator(MultipleLocator(.5))
ax00.tick_params(which = 'minor', length = 4, width = 1.5, direction = "in")
ax10.yaxis.set_minor_locator(MultipleLocator(.5))
ax10.tick_params(which = 'minor', length = 4, width = 1.5, direction = "in")
ax20.yaxis.set_minor_locator(MultipleLocator(.5))
ax20.tick_params(which = 'minor', length = 4, width = 1.5, direction = "in")
ax01.yaxis.set_minor_locator(MultipleLocator(.5))
ax01.tick_params(left = True, labelleft = False, right = False, labelright = False, which = 'minor', length = 4, width = 1.5, direction = "in")
ax11.yaxis.set_minor_locator(MultipleLocator(.5))
ax11.tick_params(left = True, labelleft = False, right = False, labelright = False, which = 'minor', length = 4, width = 1.5, direction = "in")
ax21.yaxis.set_minor_locator(MultipleLocator(.5))
ax21.tick_params(left = True, labelleft = False, right = False, labelright = False, which = 'minor', length = 4, width = 1.5, direction = "in")
# Triangles
# DATA n°1
#axis[0, 0].plot([10, 320], [57.811, 57.811], '-', color='b', linewidth=1)
#axis[1, 0].plot([10, 320], [109.2, 104.8], '-', color='b', linewidth=1)
#axis[2, 0].plot([10, 320], [132.324, 132.324], '-', color='b', linewidth=1)
axis[0, 0].plot([25, 220, 220], [56.8, 56.8, 59], '--', color='b', linewidth=1)
axis[1, 0].plot([25, 220, 220], [109, 109, 106.4], '--', color='b', linewidth=1)
axis[2, 0].plot([25, 220, 220], [133, 133, 131.8], '--', color='b', linewidth=1)
# DATA n°2
#axis[0, 1].plot([10, 320], [62.5, 69], '-', color='b', linewidth=1)
#axis[1, 1].plot([10, 320], [102.8, 96.8], '-', color='b', linewidth=1)
#axis[2, 1].plot([10, 320], [121.5, 112.5], '-', color='b', linewidth=1)
axis[0, 1].plot([25, 220, 220], [62.6, 62.6, 67], '--', color='b', linewidth=1)
axis[1, 1].plot([25, 220, 220], [102.7, 102.7, 98.2], '--', color='b', linewidth=1)
axis[2, 1].plot([25, 220, 220], [120.3, 120.3, 116], '--', color='b', linewidth=1)
# Rectangles and texts
rect_1 = mpatches.Rectangle((170, 61.2), 50, 1, alpha=0.25, facecolor='b')
rect_2 = mpatches.Rectangle((170, 103), 50, 1, alpha=0.25, facecolor='b')
rect_3 = mpatches.Rectangle((170, 120.6), 50, 1, alpha=0.25, facecolor='b')
rect_4 = mpatches.Rectangle((170, 109.2), 50, 1, alpha=0.25, facecolor='b')
rect_5 = mpatches.Rectangle((170, 55.6), 50, 1, alpha=0.25, facecolor='b')
rect_6 = mpatches.Rectangle((170, 133.2), 50, 1, alpha=0.25, facecolor='b')
axis[0, 1].add_patch(rect_1)
axis[1, 1].add_patch(rect_2)
axis[2, 1].add_patch(rect_3)
axis[1, 0].add_patch(rect_4)
axis[0, 0].add_patch(rect_5)
axis[2, 0].add_patch(rect_6)
axis[0, 1].text(175, 61.4, '~4.8°', fontsize=14, color='b')
axis[1, 1].text(175, 103.2, '~3.3°', fontsize=14, color='b')
axis[2, 1].text(175, 120.8, '~4.3°', fontsize=14, color='b')
axis[1, 0].text(175, 109.4, '~2.5°', fontsize=14, color='b')
axis[0, 0].text(175, 55.8, '~2.2°', fontsize=14, color='b')
axis[2, 0].text(175, 133.4, '~1.2°', fontsize=14, color='b')
# Defining the Y-axis limits
# DATA n°1
axis[0, 0].set_xlim(15, 310)
axis[0, 0].set_ylim(52, 64)
axis[1, 0].set_ylim(102, 114)
axis[2, 0].set_ylim(126, 138)
# DATA n°2
axis[0, 1].set_ylim(60, 72)
axis[1, 1].set_ylim(94, 106)
axis[2, 1].set_ylim(110, 122)
# Labels and graphic texts
# DATA n°1
axis[0, 0].set_title('(b)', fontsize = 30, y = 1.22, x = -0.16)
axis[0, 0].set_xlabel('T (°C)', fontsize = 18)
axis[2, 0].set_xlabel('T (°C)', fontsize = 18)
axis[0, 0].set_ylabel(r'$\Phi$ (°)', fontsize = 18)
axis[1, 0].set_ylabel(r'$\Psi$ (°)', fontsize = 18)
axis[2, 0].set_ylabel(r'$\Omega$ (°)', fontsize = 18)
# DATA n°2
#axis[0, 1].set_title('NaTaO$_2$F$_2$', fontsize = 25, y = 1.22)
axis[0, 1].set_xlabel('T (°C)', fontsize = 18)
axis[2, 1].set_xlabel('T (°C)', fontsize = 18)
axis[0, 1].set_ylabel(r'$\Phi$ (°)', fontsize = 18)
axis[1, 1].set_ylabel(r'$\Psi$ (°)', fontsize = 18)
axis[2, 1].set_ylabel(r'$\Omega$ (°)', fontsize = 18)
axis[0, 1].yaxis.set_label_position("right")
axis[1, 1].yaxis.set_label_position("right")
axis[2, 1].yaxis.set_label_position("right")
# DATA n°1
# hiding the spines between the different plots
axis[0, 0].spines['bottom'].set_visible(False)
axis[1, 0].spines['top'].set_visible(False)
axis[1, 0].spines['bottom'].set_visible(False)
axis[2, 0].spines['top'].set_visible(False)
axis[0, 0].xaxis.set_label_coords(.5, 1.2)
axis[0, 1].xaxis.set_label_coords(.5, 1.2)
# Adjusting the major ticks
axis[0, 0].xaxis.tick_top() # moving the x axis tick to the top of
axis[0, 0].tick_params(top = True, labeltop = True, bottom = False, labelbottom = False, which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
axis[1, 0].tick_params(which = 'major', direction = "in", length = 8, width = 1.5, labelsize = 14)
axis[1, 0].get_xaxis().set_visible(False) # hiding the x axis ticks
axis[2, 0].xaxis.tick_bottom() # moving the x axis tick to the top of
axis[2, 0].tick_params(which = 'major', length = 8, width = 1.5, direction = "in", labelsize = 14)
# Adjusting the number of major-ticks
axis[0, 0].locator_params(axis='y', nbins=6)
axis[0, 0].locator_params(axis='x', nbins=6)
axis[1, 0].locator_params(axis='y', nbins=6)
axis[1, 0].locator_params(axis='x', nbins=6)
axis[2, 0].locator_params(axis='y', nbins=6)
axis[2, 0].locator_params(axis='x', nbins=6)
# Adjusting the minor ticks
axis[0, 0].xaxis.set_minor_locator(MultipleLocator(10))
axis[0, 0].yaxis.set_minor_locator(MultipleLocator(.5))
axis[0, 0].tick_params(which = 'minor', length = 4, width = 1.5, direction = "in")
axis[1, 0].xaxis.set_minor_locator(MultipleLocator(10))
axis[1, 0].yaxis.set_minor_locator(MultipleLocator(.5))
axis[1, 0].tick_params(which = 'minor', length = 4, width = 1.5, direction = "in")
axis[2, 0].xaxis.set_minor_locator(MultipleLocator(10))
axis[2, 0].yaxis.set_minor_locator(MultipleLocator(.5))
axis[2, 0].tick_params(which = 'minor', length = 4, width = 1.5, direction = "in")
# DATA n°2
# hiding the spines between the different plots
axis[0, 1].spines['bottom'].set_visible(False)
axis[1, 1].spines['top'].set_visible(False)
axis[1, 1].spines['bottom'].set_visible(False)
axis[2, 1].spines['top'].set_visible(False)
# Adjusting the major ticks
axis[0, 1].xaxis.tick_top() # moving the x axis tick to the top of
axis[0, 1].tick_params(top = True, labeltop = True, bottom = False, labelbottom = False, which = 'major', direction = "in", length = 8, width = 1.5, labelsize = 14)
axis[0, 1].tick_params(right = True, labelright = True, left = False, labelleft = False, which = 'major', direction = "in", length = 8, width = 1.5, labelsize = 14)
axis[1, 1].tick_params(right = True, labelright = True, left = False, labelleft = False, which = 'major', direction = "in", length = 8, width = 1.5, labelsize = 14)
axis[2, 1].tick_params(right = True, labelright = True, left = False, labelleft = False, which = 'major', direction = "in", length = 8, width = 1.5, labelsize = 14)
axis[1, 1].get_xaxis().set_visible(False) # hiding the x axis ticks
axis[2, 1].xaxis.tick_bottom() # moving the x axis tick to the top of
# Adjusting the number of major-ticks
axis[0, 1].locator_params(axis='y', nbins=6)
axis[0, 1].locator_params(axis='x', nbins=6)
axis[1, 1].locator_params(axis='y', nbins=6)
axis[1, 1].locator_params(axis='x', nbins=6)
axis[2, 1].locator_params(axis='y', nbins=6)
axis[2, 1].locator_params(axis='x', nbins=6)
# Adjusting the minor ticks
axis[0, 1].xaxis.set_minor_locator(MultipleLocator(10))
axis[0, 1].yaxis.set_minor_locator(MultipleLocator(.5))
axis[0, 1].tick_params(right = True, labelright = True, left = False, labelleft = False, which = 'minor', length = 4, width = 1.5, direction = "in")
axis[1, 1].xaxis.set_minor_locator(MultipleLocator(10))
axis[1, 1].yaxis.set_minor_locator(MultipleLocator(.5))
axis[1, 1].tick_params(right = True, labelright = True, left = False, labelleft = False, which = 'minor', length = 4, width = 1.5, direction = "in")
axis[2, 1].xaxis.set_minor_locator(MultipleLocator(10))
axis[2, 1].yaxis.set_minor_locator(MultipleLocator(.5))
axis[2, 1].tick_params(right = True, labelright = True, left = False, labelleft = False, which = 'minor', length = 4, width = 1.5, direction = "in")
###############################################################################################################################
###########################################< Section n°2 : Adding breaks and rectangles >######################################
###############################################################################################################################
# DATA n°1
d = .015 # how big to make the diagonal lines in axes coordinates
# arguments to pass to plot, just so we don't keep repeating them
kwargs = dict(transform=axis[0, 0].transAxes, color='k', clip_on=False)
axis[0, 0].plot((-d, +d), (-d, +d), **kwargs) # top-left diagonal
axis[0, 0].plot((1 - d, 1 + d), (-d, +d), **kwargs) # top-right diagonal
kwargs.update(transform=axis[1, 0].transAxes) # switch to the bottom axes
axis[1, 0].plot((-d, +d), (1 - d, 1 + d), **kwargs) # bottom-left diagonal
axis[1, 0].plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs) # bottom-right diagonal
axis[1, 0].plot((-d, +d), (-d, +d), **kwargs) # top-left diagonal
axis[1, 0].plot((1 - d, 1 + d), (-d, +d), **kwargs) # top-right diagonal
kwargs.update(transform=axis[2, 0].transAxes) # switch to the bottom axes
axis[2, 0].plot((-d, +d), (1 - d, 1 + d), **kwargs) # bottom-left diagonal
axis[2, 0].plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs) # bottom-right diagonal
# DATA n°2
d = .015 # how big to make the diagonal lines in axes coordinates
# arguments to pass to plot, just so we don't keep repeating them
kwargs = dict(transform=axis[0, 1].transAxes, color='k', clip_on=False)
axis[0, 1].plot((-d, +d), (-d, +d), **kwargs) # top-left diagonal
axis[0, 1].plot((1 - d, 1 + d), (-d, +d), **kwargs) # top-right diagonal
kwargs.update(transform=axis[1, 1].transAxes) # switch to the bottom axes
axis[1, 1].plot((-d, +d), (1 - d, 1 + d), **kwargs) # bottom-left diagonal
axis[1, 1].plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs) # bottom-right diagonal
axis[1, 1].plot((-d, +d), (-d, +d), **kwargs) # top-left diagonal
axis[1, 1].plot((1 - d, 1 + d), (-d, +d), **kwargs) # top-right diagonal
kwargs.update(transform=axis[2, 1].transAxes) # switch to the bottom axes
axis[2, 1].plot((-d, +d), (1 - d, 1 + d), **kwargs) # bottom-left diagonal
axis[2, 1].plot((1 - d, 1 + d), (1 - d, 1 + d), **kwargs) # bottom-right diagonal
# What's cool about this is that now if we vary the distance between
# ax and ax2 via f.subplots_adjust(hspace=...) or plt.subplot_tool(),
# the diagonal lines will move accordingly, and stay right at the tips
# of the spines they are 'breaking'
f.subplots_adjust(wspace=.1, hspace=.08)
#to add the colored rectangles in the plots also the area between the figures
# DATA n°1
xmin, xmax = 220,300
_,top = f.transFigure.inverted().transform(axis[0, 0].transAxes.transform([0,1]))
_,bottom = f.transFigure.inverted().transform(axis[2, 0].transAxes.transform([0,0]))
trans = matplotlib.transforms.blended_transform_factory(axis[0, 0].transData, f.transFigure)
r_1 = matplotlib.patches.Rectangle(xy=(xmin,bottom), width=xmax-xmin, height=top-bottom, transform=trans,
fc='Grey', alpha = .25, ec='C0', lw=0)
f.add_artist(r_1)
# DATA n°2
_,top = f.transFigure.inverted().transform(axis[0, 1].transAxes.transform([0,1]))
_,bottom = f.transFigure.inverted().transform(axis[2, 1].transAxes.transform([0,0]))
trans = matplotlib.transforms.blended_transform_factory(axis[0, 1].transData, f.transFigure)
r_2 = matplotlib.patches.Rectangle(xy=(xmin,bottom), width=xmax-xmin, height=top-bottom, transform=trans,
fc='Grey', alpha = .25, ec='C0', lw=0)
f.add_artist(r_2)
###############################################################################################################################
###############################################< Section n°3 : Linear regressions >############################################
###############################################################################################################################
# DATA n°1
# Definnig the regression variables (x, y)
x1 = data_1[:11, 0]
y11 = data_1[:11, 1]
y13 = data_1[:11, 5]
y14 = data_1[:11, 7]
# Calculating the linear regression model
model11 = sm.OLS(y11, sm.add_constant(x1))
results11 = model11.fit()
model13 = sm.OLS(y13, sm.add_constant(x1))
results13 = model13.fit()
model14 = sm.OLS(y14, sm.add_constant(x1))
results14 = model14.fit()
# extract intercept b and slope m
b11, m11 = results11.params
b13, m13 = results13.params
b14, m14 = results14.params
# plot y = m*x + b
axis[0, 0].axline(xy1=(0, b11), slope = m11, linestyle='-', color='b', linewidth=1)
axis[1, 0].axline(xy1=(0, b13), slope = m13, linestyle='-', color='b', linewidth=1)
axis[2, 0].axline(xy1=(0, b14), slope = m14, linestyle='-', color='b', linewidth=1)
# DATA n°2
# Definnig the regression variables (x, y)
x2 = data_2[:11, 0]
y21 = data_2[:11, 1]
y23 = data_2[:11, 5]
y24 = data_2[:11, 7]
# Calculating the linear regression model
model21 = sm.OLS(y21, sm.add_constant(x2))
results21 = model21.fit()
model23 = sm.OLS(y23, sm.add_constant(x2))
results23 = model23.fit()
model24 = sm.OLS(y24, sm.add_constant(x2))
results24 = model24.fit()
# extract intercept b and slope m
b21, m21 = results21.params
b23, m23 = results23.params
b24, m24 = results24.params
# plot y = m*x + b
axis[0, 1].axline(xy1=(0, b21), slope = m21, linestyle='-', color='b', linewidth=1)
axis[1, 1].axline(xy1=(0, b23), slope = m23, linestyle='-', color='b', linewidth=1)
axis[2, 1].axline(xy1=(0, b24), slope = m24, linestyle='-', color='b', linewidth=1)
#plt.tight_layout()
f.savefig('figure_10-b.png', dpi=300, bbox_inches='tight')
plt.show()