Skip to content

Commit

Permalink
Change default plotting markers from a circle to a variety of symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
olgabot committed Apr 8, 2015
1 parent 87293eb commit 42cbcb8
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions flotilla/data_model/metadata.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from collections import defaultdict
import sys
import warnings
from itertools import cycle

import matplotlib as mpl
import pandas as pd
Expand Down Expand Up @@ -65,20 +66,23 @@ def __init__(self, data, phenotype_order=None, phenotype_to_color=None,
self._phenotype_to_color[phenotype] = color

self.phenotype_to_marker = phenotype_to_marker

markers = cycle(['o', '^', 's', 'v', '*', 'D', ])
if self.phenotype_to_marker is not None:
for phenotype in self.unique_phenotypes:
try:
marker = self.phenotype_to_marker[phenotype]
except KeyError:
marker = markers.next()
sys.stderr.write(
'{} does not have marker style, '
'falling back on "o" (circle)'.format(phenotype))
marker = 'o'
'falling back on "{}"'.format(phenotype, marker))
if marker not in mpl.markers.MarkerStyle.filled_markers:
correct_marker = markers.next()
sys.stderr.write(
'{} is not a valid matplotlib marker style, '
'falling back on "o" (circle)'.format(marker))
marker = 'o'
'falling back on "{}"'.format(marker, correct_marker))
marker = correct_marker
self.phenotype_to_marker[phenotype] = marker

@property
Expand Down Expand Up @@ -165,10 +169,14 @@ def phenotype_to_marker(self, value):
self._phenotype_to_marker = value
else:
sys.stderr.write('No phenotype to marker (matplotlib plotting '
'symbol) was provided, so each phenotype will be '
'plotted as a circle in visualizations.\n')
self._phenotype_to_marker = dict.fromkeys(self.unique_phenotypes,
'o')
'symbol) was provided, falling back on reasonable'
' defaults.\n')
markers = cycle(['o', '^', 's', 'v', '*', 'D', ])

def marker_factory():
return markers.next()

self._phenotype_to_marker = defaultdict(marker_factory)

@property
def phenotype_color_order(self):
Expand Down

0 comments on commit 42cbcb8

Please sign in to comment.