-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsurfaceplotter.py
More file actions
executable file
·106 lines (81 loc) · 3.43 KB
/
surfaceplotter.py
File metadata and controls
executable file
·106 lines (81 loc) · 3.43 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 22 01:27:37 2020
@author: numata
"""
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
from matplotlib.cm import ScalarMappable
import matplotlib.colors as colors
import os
import json
class SurfacePlotter:
def __init__(self, path=None):
self.path = path
def import_config(self):
if self.path is None:
config_path = 'config.json'
else:
config_path = self.path
print(config_path)
with open(config_path) as json_data_file:
config = json.load(json_data_file)
return config
def plot(self, output='output.png', use_image="./macaque_side.png"):
conf = self.import_config()
ch_loc = np.array(conf['basic']['coordination'])
cc = np.random.rand(len(ch_loc))
cmap = conf['plot_setting']['colormap_type']
v_range= conf['plot_setting']['scale']
colorbar = conf['plot_setting']['vis_colorbar']
interval =conf['plot_setting']['cbar_interval']
plt.figure(figsize=(10,7))
plt.rcParams['font.size']=conf['plot_setting']['font_size']
plt.gca().spines['right'].set_visible(False)
plt.gca().spines['left'].set_visible(False)
plt.gca().spines['top'].set_visible(False)
plt.gca().spines['bottom'].set_visible(False)
plt.tick_params(labelbottom=False,
labelleft=False,
labelright=False,
labeltop=False,
bottom=False,
left=False,
right=False,
top=False)
img = Image.open(use_image)
plt.imshow(np.asarray(img))
if cmap == 'jet':
norm = colors.Normalize(vmin=v_range[0], vmax=v_range[1])
mappable = ScalarMappable(cmap='jet',norm=norm)
elif cmap == 'viridis_r':
norm = colors.Normalize(vmin=v_range[0], vmax=v_range[1])
mappable = ScalarMappable(cmap='viridis_r',norm=norm)
elif cmap == 'Spectral_r':
norm = colors.Normalize(vmin=v_range[0], vmax=v_range[1])
mappable = ScalarMappable(cmap='Spectral_r',norm=norm)
else:
norm = colors.Normalize(vmin=0, vmax=v_range[1])
mappable = ScalarMappable(cmap='hot_r',norm=norm)
for ch in range(ch_loc.shape[0]):
im=plt.scatter(x=np.reshape(ch_loc[ch,0],-1), y=np.reshape(ch_loc[ch,1],-1),
marker = conf['plot_setting']['marker_shape'],
s = conf['plot_setting']['marker_size'],
c = cc[ch],
vmin = v_range[0], vmax = v_range[1],
linewidths="3", edgecolors="dimgray", cmap=cmap)
if colorbar == True:
colorbar_axes = plt.gcf().add_axes([0.87, 0.3, 0.02, 0.3])
cbar=plt.colorbar(mappable,cax=colorbar_axes)
cbar.ax.tick_params(labelsize=20)
cbar.set_ticks(np.round(np.arange(v_range[0], v_range[1]+interval,interval),1))
os.makedirs('output',exist_ok=True)
plt.savefig('output/'+output,
bbox_inches="tight",
dpi = conf['plot_setting']['dpi'],
transparent = conf['plot_setting']['transparent'])
plt.cla();plt.clf();plt.close()
# conf = SurfacePlotter()
# conf.plot()