Ignore:
Timestamp:
09/15/16 00:07:27 (8 years ago)
Author:
Maciej Komosinski
Message:

Introduced an option to swap (exchange) X and Y axes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • mds-and-trees/mds_plot.py

    r613 r616  
    103103
    104104
    105 def plot(coordinates, labels, dimensions, variance_fraction, jitter, flipX, flipY, outname=""):
     105def plot(coordinates, labels, dimensions, variance_fraction, jitter, flipX, flipY, swapXY, outname=""):
    106106        fig = plt.figure()
    107107
     
    118118        if flipY:
    119119                coordinates=np.hstack((coordinates[:, [0]], -coordinates[:, [1]]))
     120        if swapXY:
     121                coordinates[:,[0, 1]] = coordinates[:,[1, 0]]
    120122
    121123        add_jitter = lambda tab: rand_jitter(tab, jitter) if jitter>0 else tab
     
    158160
    159161
    160 def main(filename, dimensions=3, outname="", jitter=0, separator='\t', flipX=False, flipY=False):
     162def main(filename, dimensions=3, outname="", jitter=0, separator='\t', flipX=False, flipY=False, swapXY=False):
    161163        distances,labels = read_file(filename, separator)
    162164        embed,variance_fraction = compute_mds(distances, dimensions)
     
    165167                embed = np.array([np.insert(e, 0, 0, axis=0) for e in embed])
    166168       
    167         plot(embed, labels, dimensions, variance_fraction, jitter, flipX, flipY, outname)
     169        plot(embed, labels, dimensions, variance_fraction, jitter, flipX, flipY, swapXY, outname)
    168170
    169171
     
    177179        parser.add_argument('--flipX', required=False, dest='flipX', action='store_true')
    178180        parser.add_argument('--flipY', required=False, dest='flipY', action='store_true')
     181        parser.add_argument('--swapXY', required=False, dest='swapXY', action='store_true')
    179182        parser.set_defaults(flipX=False)
    180183        parser.set_defaults(flipY=False)
     184        parser.set_defaults(swapXY=False)
    181185
    182186        args = parser.parse_args()
    183187        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)
     188        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, args.swapXY)
Note: See TracChangeset for help on using the changeset viewer.