Changeset 613
- Timestamp:
- 09/11/16 03:59:38 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
mds-and-trees/mds_plot.py
r609 r613 103 103 104 104 105 def plot(coordinates, labels, dimensions, variance_fraction, jitter =0, outname=""):105 def plot(coordinates, labels, dimensions, variance_fraction, jitter, flipX, flipY, outname=""): 106 106 fig = plt.figure() 107 107 … … 111 111 ax = fig.add_subplot(111, projection='3d') 112 112 113 add_jitter = lambda tab : rand_jitter(tab, jitter) if jitter>0 else tab114 115 113 x_dim = len(coordinates[0]) 116 114 y_dim = len(coordinates) 117 115 116 if flipX: 117 coordinates=np.hstack((-coordinates[:, [0]], coordinates[:, [1]])) 118 if flipY: 119 coordinates=np.hstack((coordinates[:, [0]], -coordinates[:, [1]])) 120 121 add_jitter = lambda tab: rand_jitter(tab, jitter) if jitter>0 else tab 118 122 points = [add_jitter(coordinates[:, i]) for i in range(x_dim)] 119 123 120 124 if labels is not None and dimensions==2: #could be ported to 3D too 121 125 ax.scatter(*points, alpha=0) #invisible points, because we will show labels instead 122 labelconvert={'velland ':'V','velwat':'W','vpp':'P','vpa':'A'} #use this if you want to replace long names with short IDs123 colors={'velland ':'green','velwat':'blue','vpp':'red','vpa':'violet'}126 labelconvert={'velland_':'V','velwat_':'W','vpp_':'P','vpa_':'A'} #use this if you want to replace long names with short IDs 127 colors={'velland_':'green','velwat_':'blue','vpp_':'red','vpa_':'violet'} 124 128 #for point in points: 125 129 # print(point) … … 154 158 155 159 156 def main(filename, dimensions=3, outname="", jitter=0, separator='\t' ):160 def main(filename, dimensions=3, outname="", jitter=0, separator='\t', flipX=False, flipY=False): 157 161 distances,labels = read_file(filename, separator) 158 162 embed,variance_fraction = compute_mds(distances, dimensions) … … 161 165 embed = np.array([np.insert(e, 0, 0, axis=0) for e in embed]) 162 166 163 plot(embed, labels, dimensions, variance_fraction, jitter, outname)167 plot(embed, labels, dimensions, variance_fraction, jitter, flipX, flipY, outname) 164 168 165 169 … … 171 175 parser.add_argument('--sep', required=False, help='separator of the source file') 172 176 parser.add_argument('--j', required=False, help='for j>0, random jitter is added to points in the plot') 177 parser.add_argument('--flipX', required=False, dest='flipX', action='store_true') 178 parser.add_argument('--flipY', required=False, dest='flipY', action='store_true') 179 parser.set_defaults(flipX=False) 180 parser.set_defaults(flipY=False) 173 181 174 182 args = parser.parse_args() 175 set_value = lambda value, default 176 main(args.input, int(set_value(args.dim, 3)), set_value(args.output, ""), float(set_value(args.j, 0)), set_value(args.sep, "\t") )183 set_value = lambda value, default: default if value == None else value 184 main(args.input, int(set_value(args.dim, 3)), set_value(args.output, ""), float(set_value(args.j, 0)), set_value(args.sep, "\t"), args.flipX, args.flipY)
Note: See TracChangeset
for help on using the changeset viewer.