Changeset 609 for mds-and-trees


Ignore:
Timestamp:
09/02/16 00:06:41 (8 years ago)
Author:
Maciej Komosinski
Message:

Labels can have colors dependent on label text

File:
1 edited

Legend:

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

    r608 r609  
    118118        points = [add_jitter(coordinates[:, i]) for i in range(x_dim)]
    119119       
    120         if labels is not None and dimensions==2:
    121                 ax.scatter(*points, alpha=0.1) #barely visible points, because we will show labels anyway
     120        if labels is not None and dimensions==2: #could be ported to 3D too
     121                ax.scatter(*points, alpha=0) #invisible points, because we will show labels instead
    122122                labelconvert={'velland':'V','velwat':'W','vpp':'P','vpa':'A'} #use this if you want to replace long names with short IDs
     123                colors={'velland':'green','velwat':'blue','vpp':'red','vpa':'violet'}
    123124                #for point in points:
    124125                #       print(point)
    125126                for label, x, y in zip(labels, points[0], points[1]):
     127                        color='black'
    126128                        for key in labelconvert:
    127129                                if label.startswith(key):
    128130                                        label=labelconvert[key]
     131                                        color=colors[key]
    129132                        plt.annotate(
    130133                                label,
    131134                                xy = (x, y), xytext = (0, 0),
    132135                                textcoords = 'offset points', ha = 'center', va = 'center',
     136                                color = color,
     137                                alpha = 0.8,
    133138                                #bbox = dict(boxstyle = 'round,pad=0.5', fc = 'yellow', alpha = 0.5),
    134139                                #arrowprops = dict(arrowstyle = '->', connectionstyle = 'arc3,rad=0')
Note: See TracChangeset for help on using the changeset viewer.