-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplot_multiple.py
More file actions
192 lines (147 loc) · 7.46 KB
/
Copy pathplot_multiple.py
File metadata and controls
192 lines (147 loc) · 7.46 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
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
import os.path
from matplotlib import pyplot as plt
from matplotlib import image as img
class PlotMultiple():
def __init__(self):
self.ax = None
self.fig = None
self.index_row = 0
self.index_col = 0
self.nrow = 1
self.ncol = 1
self.axhere = None
def start_multiple_plot(self, nrow, ncol):
self.nrow = nrow
self.ncol = ncol
# self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(8, 6), frameon=False,
# gridspec_kw={'wspace': 0, 'hspace': 0})
# self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(15.9, 18), frameon=False,gridspec_kw={'wspace': 0, 'hspace': 0})
# self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(16, 12), frameon=False,gridspec_kw={'wspace': 0, 'hspace': 0})
self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(16, 12), frameon=False,
gridspec_kw={'wspace': 0, 'hspace': 0})
# self.ax.set_axis_off()
# self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(8, 6), frameon=False,
# gridspec_kw={'wspace': 0, 'hspace': 0})
def start_multiple_plot_advanced(self, nrow, ncol, xfigsize, yfigsize, wspace, hspace, frameon):
self.nrow = nrow
self.ncol = ncol
self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(xfigsize, yfigsize), frameon=frameon,
gridspec_kw={'wspace': wspace, 'hspace': hspace})
def start_multiple_plot_polar(self, nrow, ncol, xfigsize, yfigsize, wspace, hspace, frameon):
self.nrow = nrow
self.ncol = ncol
self.fig, self.ax = plt.subplots(nrow, ncol, figsize=(xfigsize, yfigsize), frameon=frameon,
gridspec_kw={'wspace': wspace, 'hspace': hspace},
subplot_kw={'projection': 'polar'})
def set_text(self, x, y, s):
plt.text(x, y, s, fontsize=10, backgroundcolor='w')
def set_text_size(self, x, y, s,fontsize):
plt.text(x, y, s, fontsize=fontsize, backgroundcolor='w')
def get_axes(self, index_row, index_col):
if self.nrow > 1 and self.ncol > 1:
axhere = self.ax[index_row, index_col]
elif self.nrow == 1 and self.ncol > 1:
axhere = self.ax[index_col]
if self.nrow > 1 and self.ncol == 1:
axhere = self.ax[index_row]
return axhere
def plot_blank(self, index_row, index_col):
if self.nrow > 1 and self.ncol > 1:
axhere = self.ax[index_row, index_col]
elif self.nrow == 1 and self.ncol > 1:
axhere = self.ax[index_col]
if self.nrow > 1 and self.ncol == 1:
axhere = self.ax[index_row]
axhere.axis('off')
def plot_blank_with_title(self, index_row, index_col, title):
if self.nrow > 1 and self.ncol > 1:
axhere = self.ax[index_row, index_col]
elif self.nrow == 1 and self.ncol > 1:
axhere = self.ax[index_col]
if self.nrow > 1 and self.ncol == 1:
axhere = self.ax[index_row]
axhere.set_xticks([])
axhere.set_yticks([])
if title is not None:
axhere.set_title(title)
def plot_image_hypernets(self,file_img,index_row,index_col,title):
if self.nrow > 1 and self.ncol > 1:
axhere = self.ax[index_row, index_col]
elif self.nrow == 1 and self.ncol > 1:
axhere = self.ax[index_col]
if self.nrow > 1 and self.ncol == 1:
axhere = self.ax[index_row]
from PIL import Image
image = Image.open(file_img)
rimage = image.rotate(270,expand=True)
axhere.imshow(rimage)
w, h = rimage.size
##central point
axhere.axvline(w / 2, 0.48,0.52,color='red', linewidth=0.25)
axhere.axhline(h / 2, 0.48, 0.52, color='red', linewidth=0.25)
##grid
incremx = int(w/4)
incremy = int(h/4)
for x in range(0,w,incremx):
axhere.axvline(x, color='red', linewidth=0.5)
for y in range(0,h,incremy):
axhere.axhline(y, color='red', linewidth=0.5)
if title is not None:
axhere.set_title(title)
axhere.set_xticks([])
axhere.set_yticks([])
def plot_image_title(self, file_img, index_row, index_col, title):
image = img.imread(file_img)
if self.nrow > 1 and self.ncol > 1:
axhere = self.ax[index_row, index_col]
elif self.nrow == 1 and self.ncol > 1:
axhere = self.ax[index_col]
if self.nrow > 1 and self.ncol == 1:
axhere = self.ax[index_row]
image_end = image
axhere.imshow(image_end)
if title is not None:
axhere.set_title(title)
axhere.set_xticks([])
axhere.set_yticks([])
def plot_image(self, file_img, index_row, index_col):
image = img.imread(file_img)
if self.nrow > 1 and self.ncol > 1:
axhere = self.ax[index_row, index_col]
elif self.nrow == 1 and self.ncol > 1:
axhere = self.ax[index_col]
if self.nrow > 1 and self.ncol == 1:
axhere = self.ax[index_row]
image_end = image
axhere.imshow(image_end)
axhere.axis(False)
def tigth_layout(self):
self.fig.tight_layout()
def set_global_legend(self, handles, str_legend):
# self.fig.legend(handles, str_legend, fontsize = 8, loc='lower center', ncol=len(str_legend), markerscale=1.5,bbox_to_anchor=(0.55,0.08))
self.fig.legend(handles, str_legend, fontsize=8, loc='lower center', ncol=len(str_legend), markerscale=1.0,
bbox_to_anchor=(0.55, 0.06))
# self.fig.legend(handles, str_legend, fontsize=8, loc='lower center', ncol=len(str_legend), markerscale=1.0)
def set_global_legend_2(self, handles, str_legend):
# self.fig.legend(handles, str_legend, fontsize = 8, loc='lower center', ncol=len(str_legend), markerscale=1.5,bbox_to_anchor=(0.55,0.08))
self.fig.legend(handles, str_legend, fontsize=11, loc='lower center', ncol=len(str_legend), markerscale=1.0,
bbox_to_anchor=(0.50, -0.03))
def set_global_legend_3(self, handles, str_legend):
# self.fig.legend(handles, str_legend, fontsize = 8, loc='lower center', ncol=len(str_legend), markerscale=1.5,bbox_to_anchor=(0.55,0.08))
handles_new = [handles[0], handles[4], handles[1], handles[5], handles[2], handles[6], handles[3], handles[7]]
str_legend_new = [str_legend[0], str_legend[4], str_legend[1], str_legend[5], str_legend[2], str_legend[6],
str_legend[3], str_legend[7]]
self.fig.legend(handles_new, str_legend_new, fontsize=11, loc='lower center', ncol=4, markerscale=1.0,
bbox_to_anchor=(0.53, 0.04), frameon=False)
def save_fig(self, file_out):
if file_out.endswith('.tif'):
plt.savefig(file_out, dpi=300, bbox_inches='tight', pil_kwargs={"compression": "tiff_lzw"})
else:
plt.savefig(file_out, dpi=300, bbox_inches='tight', facecolor='white')
def save_fig_with_resolution(self, file_out,resolution):
if file_out.endswith('.tif'):
plt.savefig(file_out, dpi=resolution, bbox_inches='tight', pil_kwargs={"compression": "tiff_lzw"})
else:
plt.savefig(file_out, dpi=resolution, bbox_inches='tight', facecolor='white')
def close_plot(self):
plt.close()