diff --git a/tfields/lib/util.py b/tfields/lib/util.py index 41a8ffc368c4e1d6b6ee61d01d988549e49d1ab7..ebec7c40c229aedd282ca6f07bf9daa8d51b60bc 100644 --- a/tfields/lib/util.py +++ b/tfields/lib/util.py @@ -67,6 +67,7 @@ def multi_sort(array, *others, **kwargs): method (function): sorting function. Default is 'sorted' ...: further arguments are passed to method. Default rest is 'key=array[0]' + reversed (bool): wether to reverse the results or not Examples: >>> from tfields.lib.util import multi_sort >>> multi_sort([1,2,3,6,4], [1,2,3,4,5]) @@ -79,10 +80,24 @@ def multi_sort(array, *others, **kwargs): >>> multi_sort([1,2,3,6,4], [1,2,3,4,5], [6,5,4,3,2]) [[1, 2, 3, 4, 6], [1, 2, 3, 5, 4], [6, 5, 4, 2, 3]] + Reverse argument + >>> multi_sort([1,2,3,6,4], [1,2,3,4,5], [6,5,4,3,2], reverse=True) + [[6, 4, 3, 2, 1], [4, 5, 3, 2, 1], [3, 2, 4, 5, 6]] + """ method = kwargs.pop('method', None) if method is None: method = sorted if 'key' not in kwargs: kwargs['key'] = lambda pair: pair[0] - return [list(x) for x in zip(*method(zip(array, *others), **kwargs))] + reverse = kwargs.pop('reverse', False) + if not reverse: + cast_type = list + else: + cast_type = lambda x: list(reversed(x)) + return [cast_type(x) for x in zip(*method(zip(array, *others), **kwargs))] + + +if __name__ == '__main__': + import doctest + doctest.testmod() diff --git a/tfields/plotting/mpl.py b/tfields/plotting/mpl.py index 1116e6b0231d50276edce8424cd1d01c35508eef..2577abd598eb105b41c043d3ce43b75bc5bcc592 100644 --- a/tfields/plotting/mpl.py +++ b/tfields/plotting/mpl.py @@ -697,9 +697,30 @@ def set_legend(axis, artists, **kwargs): for artist in artists: if isinstance(artist, list): handles.append(artist[0]) + elif isinstance(artist, tuple): + tuple_handle = tuple() + for sub_artist in artist: + if isinstance(sub_artist, list): + tuple_handle += (sub_artist[0],) + else: + tuple_handle += (sub_artist,) + handles.append(tuple_handle) else: handles.append(artist) + if labels is None and any([isinstance(h, tuple) for h in handles]): + labels = [] + for h in handles: + if isinstance(h, tuple): + sub_labels = [sub_h.get_label() for sub_h in h] + label = sub_labels[0] + for sub_label in sub_labels[1:]: + if not sub_label.startswith('_'): + label += sub_label + else: + label = h.get_label() + labels.append(label) + if table and labels is None and ncol is None: table_title = kwargs.pop('table_title', '') labels = np.array([h.get_label() for h in handles]) diff --git a/tfields/plotting/tfields.mplstyle b/tfields/plotting/tfields.mplstyle index d11db1172da03065d26a35970793a4d7f15404a4..635db46f9e10fd820c2e73c5f140635dec1d6dc4 100644 --- a/tfields/plotting/tfields.mplstyle +++ b/tfields/plotting/tfields.mplstyle @@ -35,9 +35,4 @@ image.cmap: viridis text.usetex : True font.family : serif font.size : 40 # 20 was a duplicate definition -# mathtext.fontset = 'custom' -# mathtext.rm = 'Bitstream Vera Sans' -# mathtext.it = 'Bitstream Vera Sans:italic' -# mathtext.bf = 'Bitstream Vera Sans:bold' -# mathtext.fontset = 'stix' -# font.family = 'STIXGeneral' +text.latex.preamble : \usepackage{amsmath} # for \text etc